admin管理员组文章数量:1332982
I have a Next.js application hosted on Vercel at example. I also have an API hosted at api.example, which receives requests from the frontend. However, when I try to log the client IP address in the API, I only see the IP address of example (the Vercel server) instead of the actual client IP address.
Here’s what I’ve tried so far:
- Reading req.headers['x-forwarded-for']: I added middleware on my API to log this header, but it always seems to contain the Vercel server IP.
I have a Next.js application hosted on Vercel at example. I also have an API hosted at api.example, which receives requests from the frontend. However, when I try to log the client IP address in the API, I only see the IP address of example (the Vercel server) instead of the actual client IP address.
Here’s what I’ve tried so far:
- Reading req.headers['x-forwarded-for']: I added middleware on my API to log this header, but it always seems to contain the Vercel server IP.
1 Answer
Reset to default 1Are you reading the first IP of the returned array, which should be the client one?
const clientIp = (req.headers['x-forwarded-for'] || '').split(',')[0].trim()
本文标签: nodejsHow to Get the Client IP Address in a Nextjs Application Hosted on VercelStack Overflow
版权声明:本文标题:node.js - How to Get the Client IP Address in a Next.js Application Hosted on Vercel? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742344452a2457242.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论