import { promises as fs } from 'fs'; import path from 'path'; import type { VercelRequest, VercelResponse } from '@vercel/node'; export default async function handler(req: VercelRequest, res: VercelResponse) { try { const filePath = path.join(process.cwd(), 'BSR.xlsx'); try { await fs.access(filePath); } catch { return res.status(404).json({ error: 'BSR data file not found' }); } const fileBuffer = await fs.readFile(filePath); res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.setHeader('Content-Disposition', 'attachment; filename="BSR.xlsx"'); res.setHeader('Cache-Control', 'public, max-age=3600'); // Convert Buffer to ArrayBuffer before sending for fetch compatibility on client res.send(fileBuffer); } catch (error) { console.error('Error serving BSR Excel file:', error); res.status(500).json({ error: 'Failed to serve BSR file' }); } }