Proxy-addr is a Node.js module that serves as an advanced solution to determine the address of a proxied web request. In a web context where many requests may be routed through various proxies before reaching its target, this utility helps decipher the original source of the request.
The proxy-addr module can be utilized by first installing it through the npm registry using the command $ npm install proxy-addr. Upon installation, you can import the module into your JavaScript file using var proxyaddr = require('proxy-addr').
There are three primary functions available:
proxyaddr(req, trust): This returns the address of the request based on the trust parameter, which is a function that should return true for trusted addresses and false for untrusted ones.Example:
proxyaddr(req, function (addr) { return addr === '127.0.0.1' })
proxyaddr(req, function (addr, i) { return i < 1 })
proxyaddr.all(req, [trust]): This returns all addresses of the request, optionally stopping at the first untrusted. The optional trust argument takes the same arguments as trust does in proxyaddr(req, trust).Example:
proxyaddr.all(req, 'loopback')
proxyaddr.compile(val): This compiles argument val into a trust function. This function takes the same arguments as trust does in proxyaddr(req, trust) and returns a function suitable for proxyaddr(req, trust).Example:
var trust = proxyaddr.compile('loopback')
var addr = proxyaddr(req, trust)
The proxy-addr documentation is embedded within the README file in the project repository on GitHub. It doesn't have a dedicated documentation website. The GitHub repository URL is https://github.com/jshttp/proxy-addr, where you can access detailed information about the features and functions of the proxy-addr npm package.