lundi 24 février 2020

Getting IP Of Direct Machine Calling NodeJS Server/Machine

So I'm trying to create a nodejs program that runs on one server and can be called either from either a person's code/machine or from another server that's running a website that might call the code for its own purposes. Essentially, I always want to get the direct machine calling the nodejs machine. But if I do req.connection.remoteAddress or req.headers['x-forwarded-for'] using express-serve-static-core, that gets me the browser that has called the web server (obviously) that calls the nodejs server, not the web server itself. Hostname() (not req.hostname, just hostname which is os.hostname) obviously gets the server IP that the nodejs is running on.

to clarify, if the web code is run in, say, a matlab code or someone else's code makes call to the nodejs server, the ip address in the req methods above might work, but not if it's

browser/client machine -> web server machine -> nodejs machine

I want to get the web server machine's.

I'm not sure what would be the best means that would get the IP of the webserver or another machine making a direct call to the nodejs server.




Aucun commentaire:

Enregistrer un commentaire