Files

39 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2026-03-02 15:22:12 +01:00
import type { VercelRequest, VercelResponse } from '@vercel/node';
const BSR_DROPBOX_URL = "https://www.dropbox.com/scl/fi/r32r9x6r7bvgg6ckiaowk/BSR.xlsx?rlkey=vka50xyhc637riq901qo5bk16&st=y6ys2oz8&dl=1";
2026-03-02 15:22:12 +01:00
export default async function handler(req: VercelRequest, res: VercelResponse) {
// CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
return res.status(200).end();
}
try {
console.log('[fetch-bsr] Fetching BSR.xlsx from Dropbox...');
const response = await fetch(BSR_DROPBOX_URL, {
cache: 'no-store',
headers: {
'Pragma': 'no-cache',
'Cache-Control': 'no-cache'
}
});
if (!response.ok) {
throw new Error(`Dropbox responded with ${response.status}`);
2026-03-02 15:22:12 +01:00
}
const buffer = await response.arrayBuffer();
console.log('[fetch-bsr] Successfully fetched BSR Excel, size:', buffer.byteLength);
2026-03-02 15:22:12 +01:00
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.status(200).send(Buffer.from(buffer));
} catch (error: any) {
console.error('[fetch-bsr] Error:', error);
res.status(500).json({ error: error.message });
2026-03-02 15:22:12 +01:00
}
}