3 ms·
The workflow goes like this: I’m working on a React application where users make API requests and send data. I need to capture the user’s public IP address befo
by bqc 2y ago
The workflow goes like this: I’m working on a React application where users make API requests and send data. I need to capture the user’s public IP address before storing the data. Currently, my method returns the local IP address, but I need the public IP address instead.
- solardev 2y agoI'm still not sure if this is what you're asking, but have you already tried checking `req.headers['x-forwarded-for']`? Normally node just knows the incoming request IP (that's how it was reached to begin with), but if you're behind another server or proxy, sometimes the original IP gets forwarded instead. If that's not what you're asking... can you please clarify your client-server architecture (if there even is one?) Where is Node running? Is it on an internet-facing server, acting as a backend? Or are you doing some sort of local desktop app? Is Node using its own http systems to act as a server, or is there some other web server or reverse proxy running in front of it? Is React running on the client's browser, separate from Node altogether? Or are you using React on the backend too (like in Next or similar)?