// Vercel serverless function — proxies the Dropbox file server-side (no CORS)
export default async function handler(req, res) {
  const fileUrl =
    'https://dl.dropboxusercontent.com/scl/fi/nkyabkq2jdwfudof2ovrl/Data-Matrix.xlsx' +
    '?rlkey=1cz5fuabwipqqivihii7sybw0&st=io0g4wvb&dl=1';

  try {
    const upstream = await fetch(fileUrl, {
      headers: { 'User-Agent': 'Mozilla/5.0' },
    });

    if (!upstream.ok) {
      return res.status(upstream.status).send(`Dropbox error: ${upstream.status}`);
    }

    const buffer = await upstream.arrayBuffer();
    res.setHeader('Content-Type', 'application/octet-stream');
    res.setHeader('Cache-Control', 'no-store');
    res.send(Buffer.from(buffer));
  } catch (err) {
    res.status(500).send('Proxy error: ' + err.message);
  }
}
