import fetch from 'node-fetch';

export default async function handler(req:any, res:any) {
  const userAgent = req.headers['user-agent'];

  try {
    // Fetch the public IP address
    const ipRes = await fetch('https://api.ipify.org?format=json');
    const ipData:any = await ipRes.json();
    const ip = ipData.ip;

    res.status(200).json({ userAgent, ip });
  } catch (error) {
    res.status(500).json({ error: 'Failed to fetch IP address'});
  }
}
