Search code examples
node.jsazureazure-functions

How to get client IP address in Azure Functions node.js?


I have an Azure function written on node.js. How could I retrieved an IP address of a client that called the function?

What I've found so far:

  1. An answer to the same question, but using C#.
  2. It is possible to read it from headers:

    module.exports = function (context, req) {
        var ip = req.headers['x-forwarded-for']    
    }
    

Is it reliable to get the ip this way, since it can be easily changed on the way to the function?


Solution

  • Yes it is reliable, because Azure web server will overwrite x-forwarded-for as it knows it is forwarding from load balancer.