'how to get client IP address with node grpc
Earlier I used below code to get the client IP on express.js
req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress
would like to know what is the way to get IP of client with grpc node application. I tried getPeer() which gives always ipv4:127.0.0.1:33944 even when API call is from outside.
Does something equivalent to below go code work?
call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR).toString();
Solution 1:[1]
You can get the client IP and port by:
const SayHello = async function (call, callback) {
const IPandPort = call.getPeer(); // like 127.0.0.1:8080 or just get 127.0.0.1
console.log(IPandPort);
}
See these issues to get more information:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
