read IP of the Request POST
Answered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
I am trying to figure out how to get the IP address of the client that is making the request. Currently it is undifined
I tried the browser (axios) and Postman. Both show up in the request as undifined.
I tried the browser (axios) and Postman. Both show up in the request as undifined.
Answered by tafutada777
it used to be easier to get a client ip address from the HTTP header like
but these days, we use cloud servers, serverless or managed such as AWS, GCP, so the header could be modified/hide by load balancer, reverse-proxy and so on.
so it depends on your hosting service, environment.
in my case, i host a Next.js on kubernetes container, so the said header returns a LB's ip address.
req.headers['x-forwarded-for']but these days, we use cloud servers, serverless or managed such as AWS, GCP, so the header could be modified/hide by load balancer, reverse-proxy and so on.
so it depends on your hosting service, environment.
in my case, i host a Next.js on kubernetes container, so the said header returns a LB's ip address.
5 Replies
may i see the code. and tell me where to host, Vercel or self hosted?
btw you don’t need to doubt client side. IP address is passed via IP layer so web browsers, postman, cURL has nothing to do with it. only servers like proxy and your server affect the client ip address, which is extracted from IP layer.
@tafutada777 btw you don’t need to doubt client side. IP address is passed via IP layer so web browsers, postman, cURL has nothing to do with it. only servers like proxy and your server affect the client ip address, which is extracted from IP layer.
Alligator mississippiensisOP
self hosted.
I just wanted to restrict the POST request to 1 IP only. There is no code yet besides a console.log for the req
I just wanted to restrict the POST request to 1 IP only. There is no code yet besides a console.log for the req
it used to be easier to get a client ip address from the HTTP header like
but these days, we use cloud servers, serverless or managed such as AWS, GCP, so the header could be modified/hide by load balancer, reverse-proxy and so on.
so it depends on your hosting service, environment.
in my case, i host a Next.js on kubernetes container, so the said header returns a LB's ip address.
req.headers['x-forwarded-for']but these days, we use cloud servers, serverless or managed such as AWS, GCP, so the header could be modified/hide by load balancer, reverse-proxy and so on.
so it depends on your hosting service, environment.
in my case, i host a Next.js on kubernetes container, so the said header returns a LB's ip address.
Answer
if you can use LB, firewall, you can set IP filter there instead of app side, setting white list such as your VPN ip.