akc42
akc42

Reputation: 5001

nodejs http2 request - where can I find the clients ip address

I am building a complex SPA using Polymer to replicate an Access Application. I want to use http2 to avoid the maintenance nightmare of merging source files to get appropriate performance.

I have built myself the start of the application, log in via a sql server database. and am now starting to debug things.

I am trying to retrieve the clientip address using answers I have found on here

var ip = req.headers['x-forwarded-for'] ||
   req.connection.remoteAddress ||
   req.socket.remoteAddress ||
   req.connection.socket.remoteAddress;

but unfortunately at this point the server crashes. Digging around with the debugger (given req is the request object) there is no 'x-forwarded-for'header, no connection object (except inside socket) and this is what kills this statement as can't access remoteAddress of undefined. But I cannot find a remoteaddress field in any object derived from req.

I am using https://github.com/molnarg/node-http2 which appears to be the only implementation around. There is some mention of endpoint.js library in the documentation but the links are broken, so I have no idea how to access an endpoint object.

In order to get the correct certificates, I am using the ones from pastrial.hartley-consultants.com and changed my in house dns server to give me my development machine as its ip address. I am accessing it via a browser on the same machine. So client and server machines should both have 192.168.0.xx IP addresses which just happen to be the same.

So question is - where is the IP address of the client exposed to the server (or indeed is it in http2)

Upvotes: 4

Views: 844

Answers (1)

akc42
akc42

Reputation: 5001

The simple answer is it is in req.remoteAddress

Upvotes: 2

Related Questions