proxy-addr

中文文档
2.0.8发布于 2026/09/15MIT构建来源已验证近 30 天下载 4.8亿

Determine address of proxied request

原始使用文档
文档目录8 节
  1. Install
  2. API
  3. proxyaddr(req, trust)
  4. proxyaddr.all(req, [trust])
  5. proxyaddr.compile(val)
  6. Testing
  7. Benchmarks
  8. License

proxy-addr

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Determine address of proxied request

Install

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install proxy-addr

API

var proxyaddr = require('proxy-addr')

proxyaddr(req, trust)

Return the address of the request, using the given trust parameter.

The trust argument is a function that returns true if you trust the address, false if you don't. The closest untrusted address is returned.

proxyaddr(req, function (addr) { return addr === '127.0.0.1' })
proxyaddr(req, function (addr, i) { return i < 1 })

The trust argument may also be a single IP address string or an array of trusted addresses, as plain IP addresses, CIDR-formatted strings, or IP/netmask strings.

proxyaddr(req, '127.0.0.1')
proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])
proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])

This module also supports IPv6. Your IPv6 addresses will be normalized automatically (i.e. fe80::00ed:1 equals fe80:0:0:0:0:0:ed:1).

proxyaddr(req, '::1')
proxyaddr(req, ['::1/128', 'fe80::/10'])

This module will automatically work with IPv4-mapped IPv6 addresses as well to support node.js in IPv6-only mode. This means that you do not have to specify both ::ffff:a00:1 and 10.0.0.1.

As a convenience, this module also takes certain pre-defined names in addition to IP addresses, which expand into IP addresses:

proxyaddr(req, 'loopback')
proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])
  • loopback: IPv4 and IPv6 loopback addresses (like ::1 and 127.0.0.1).
  • linklocal: IPv4 and IPv6 link-local addresses (like fe80::1:1:1:1 and 169.254.0.1).
  • uniquelocal: IPv4 private addresses and IPv6 unique-local addresses (like fc00:ac:1ab5:fff::1 and 192.168.0.1).

When trust is specified as a function, it will be called for each address to determine if it is a trusted address. The function is given two arguments: addr and i, where addr is a string of the address to check and i is a number that represents the distance from the socket address.

proxyaddr.all(req, [trust])

Return all the addresses of the request, optionally stopping at the first untrusted. This array is ordered from closest to furthest (i.e. arr[0] === req.connection.remoteAddress).

proxyaddr.all(req)

The optional trust argument takes the same arguments as trust does in proxyaddr(req, trust).

proxyaddr.all(req, 'loopback')

proxyaddr.compile(val)

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).

var trust = proxyaddr.compile('loopback')
var addr = proxyaddr(req, trust)

This function is meant to be optimized for use against every request. It is recommend to compile a trust function up-front for the trusted configuration and pass that to proxyaddr(req, trust) for each request.

Testing

$ npm test

Benchmarks

$ npm run-script bench

License

MIT

版本与发布记录

proxy-addr 共发布 28 个版本,首次发布于 2014/05/05;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.8latest2026/09/151 个月前
2.0.72021/06/015 年前
2.0.62020/02/246 年前
2.0.52019/04/177 年前
2.0.42018/07/278 年前
2.0.32018/02/208 年前

关于 proxy-addr 的常见问题

proxy-addr 是什么?

Determine address of proxied request

如何安装 proxy-addr?

在项目目录运行 npm install proxy-addr,或使用 pnpm add / yarn add / bun add。

proxy-addr 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/proxy-addr 是否存在。

proxy-addr 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 0.10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

proxy-addr 可以商用吗?

proxy-addr 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

proxy-addr 的下载量有多少?

根据 npm 官方下载统计,proxy-addr 在 2026/10/05 – 2026/11/03 这 30 天内被下载 476,984,256 次,日均约 15,899,475 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

proxy-addr 还在维护吗?

最新版本 2.0.8 发布于 2026/09/15(1 个月前);至今共发布 28 个版本,其中过去 12 个月发布了 1 个;首次发布于 2014/05/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。