mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:35:24 +02:00
- Rewrite api/fetch-bsr.ts to proxy BSR.xlsx from the Dropbox URL, matching the same pattern as fetch-buybox.ts and other data sources - Add /api/fetch-bsr proxy in vite.config.ts for local dev Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
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";
|
|
|
|
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}`);
|
|
}
|
|
|
|
const buffer = await response.arrayBuffer();
|
|
console.log('[fetch-bsr] Successfully fetched BSR Excel, size:', buffer.byteLength);
|
|
|
|
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 });
|
|
}
|
|
}
|