diff --git a/src/pages/api/ip.ts b/src/pages/api/ip.ts index 2b6503b..3009829 100644 --- a/src/pages/api/ip.ts +++ b/src/pages/api/ip.ts @@ -9,15 +9,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }) } - console.log('x-vercel-forwarded-for' ,req.headers['x-vercel-forwarded-for']) - console.log('x-vercel-ip-country' ,req.headers['x-vercel-ip-country']) - console.log('x-vercel-ip-country-region' ,req.headers['x-vercel-ip-country-region']) - console.log('x-vercel-ip-city' ,req.headers['x-vercel-ip-city']) - console.log('x-vercel-ip-longitude' ,req.headers['x-vercel-ip-longitude']) - console.log('x-vercel-ip-latitude' ,req.headers['x-vercel-ip-latitude']) - console.log('x-vercel-ip-timezone' ,req.headers['x-vercel-ip-timezone']) + // TODO: Use these values instead of making a request to ip-api.com + // console.log('x-vercel-forwarded-for' ,req.headers['x-vercel-forwarded-for']) + // console.log('x-vercel-ip-country' ,req.headers['x-vercel-ip-country']) + // console.log('x-vercel-ip-country-region' ,req.headers['x-vercel-ip-country-region']) + // console.log('x-vercel-ip-city' ,req.headers['x-vercel-ip-city']) + // console.log('x-vercel-ip-longitude' ,req.headers['x-vercel-ip-longitude']) + // console.log('x-vercel-ip-latitude' ,req.headers['x-vercel-ip-latitude']) + // console.log('x-vercel-ip-timezone' ,req.headers['x-vercel-ip-timezone']) - const response = await fetch('http://ip-api.com/json/') + const ipAddress = req.headers['x-vercel-forwarded-for'] as string + const response = await fetch(`http://ip-api.com/json/${ipAddress}`) const data = await response.json() const { status, query, ...rest } = data @@ -27,4 +29,4 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const ipInfo = { ...rest, ipAddress: query } as IpAddressInfo res.status(200).json({ ...ipInfo }) -} \ No newline at end of file +}