{"name":"@fastify/proxy-addr","description":"Determine address of proxied request","version":"5.0.0-pre.fv5.1","main":"index.js","type":"commonjs","types":"types/index.d.ts","author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"license":"MIT","keywords":["ip","proxy","x-forwarded-for"],"repository":{"type":"git","url":"git+https://github.com/fastify/proxy-addr.git"},"bugs":{"url":"https://github.com/fastify/proxy-addr/issues"},"homepage":"https://github.com/fastify/proxy-addr#readme","dependencies":{"@fastify/forwarded":"^2.2.0","ipaddr.js":"^2.1.0"},"devDependencies":{"@fastify/pre-commit":"^2.1.0","@types/node":"^20.12.7","beautify-benchmark":"0.2.4","benchmark":"2.1.4","c8":"^7.14.0","standard":"^17.1.0","tape":"^5.7.5","tsd":"^0.31.0"},"scripts":{"bench":"node benchmark/index.js","lint":"standard","lint:fix":"standard --fix","test":"npm run test:unit && npm run test:typescript","test:typescript":"tsd","test:unit":"c8 tape test/**/*.js"},"_id":"@fastify/proxy-addr@5.0.0-pre.fv5.1","readme":"# proxy-addr\n\n![CI](https://github.com/fastify/proxy-addr/workflows/CI/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/@fastify/proxy-addr.svg?style=flat)](https://www.npmjs.com/package/@fastify/proxy-addr)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nDetermine address of proxied request.\n\nForked from https://github.com/jshttp/proxy-addr to address https://github.com/jshttp/forwarded/pull/9.\n\n## Install\n\n```sh\n$ npm i @fastify/proxy-addr\n```\n\n## API\n\n<!-- eslint-disable no-unused-vars -->\n\n```js\nvar proxyaddr = require('@fastify/proxy-addr')\n```\n\n### proxyaddr(req, trust)\n\nReturn the address of the request, using the given `trust` parameter.\n\nThe `trust` argument is a function that returns `true` if you trust\nthe address, `false` if you don't. The closest untrusted address is\nreturned.\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, function (addr) { return addr === '127.0.0.1' })\nproxyaddr(req, function (addr, i) { return i < 1 })\n```\n\nThe `trust` arugment may also be a single IP address string or an\narray of trusted addresses, as plain IP addresses, CIDR-formatted\nstrings, or IP/netmask strings.\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, '127.0.0.1')\nproxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])\nproxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])\n```\n\nThis module also supports IPv6. Your IPv6 addresses will be normalized\nautomatically (i.e. `fe80::00ed:1` equals `fe80:0:0:0:0:0:ed:1`).\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, '::1')\nproxyaddr(req, ['::1/128', 'fe80::/10'])\n```\n\nThis module will automatically work with IPv4-mapped IPv6 addresses\nas well to support node.js in IPv6-only mode. This means that you do\nnot have to specify both `::ffff:a00:1` and `10.0.0.1`.\n\nAs a convenience, this module also takes certain pre-defined names\nin addition to IP addresses, which expand into IP addresses:\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr(req, 'loopback')\nproxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])\n```\n\n  * `loopback`: IPv4 and IPv6 loopback addresses (like `::1` and\n    `127.0.0.1`).\n  * `linklocal`: IPv4 and IPv6 link-local addresses (like\n    `fe80::1:1:1:1` and `169.254.0.1`).\n  * `uniquelocal`: IPv4 private addresses and IPv6 unique-local\n    addresses (like `fc00:ac:1ab5:fff::1` and `192.168.0.1`).\n\nWhen `trust` is specified as a function, it will be called for each\naddress to determine if it is a trusted address. The function is\ngiven two arguments: `addr` and `i`, where `addr` is a string of\nthe address to check and `i` is a number that represents the distance\nfrom the socket address.\n\n### proxyaddr.all(req, [trust])\n\nReturn all the addresses of the request, optionally stopping at the\nfirst untrusted. This array is ordered from closest to furthest\n(i.e. `arr[0] === req.connection.remoteAddress`).\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr.all(req)\n```\n\nThe optional `trust` argument takes the same arguments as `trust`\ndoes in `proxyaddr(req, trust)`.\n\n<!-- eslint-disable no-undef -->\n\n```js\nproxyaddr.all(req, 'loopback')\n```\n\n### proxyaddr.compile(val)\n\nCompiles argument `val` into a `trust` function. This function takes\nthe same arguments as `trust` does in `proxyaddr(req, trust)` and\nreturns a function suitable for `proxyaddr(req, trust)`.\n\n<!-- eslint-disable no-undef, no-unused-vars -->\n\n```js\nvar trust = proxyaddr.compile('loopback')\nvar addr = proxyaddr(req, trust)\n```\n\nThis function is meant to be optimized for use against every request.\nIt is recommend to compile a trust function up-front for the trusted\nconfiguration and pass that to `proxyaddr(req, trust)` for each request.\n\n## Testing\n\n```sh\n$ npm test\n```\n\n## Benchmarks\n\n```sh\n$ npm run-script bench\n```\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md","gitHead":"e6cf439378027059e18ba1e3bb525f7f5ed31fea","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-wjjSEiBJh3Qang60As/90TlPwE/ziiIzEbPtJDCYEeGyRUuR/ZVaz/kKs0PVgWrrD6kHsQVFM7Hf6aRvrVjjWg==","shasum":"730274ba7dea1e6bd18f17bbcefd4db41823ed19","tarball":"http://registry-npm.ywwl.com/@fastify/proxy-addr/download/@fastify/proxy-addr-5.0.0-pre.fv5.1.tgz","fileCount":18,"unpackedSize":36548,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDC+KoOieUzXzAlq076PeD0zKp5cMYvsCP8OyzIP7VfHgIhANbj/KNCVsU89SZjoZ/dhdV/pWb85pFMSsf7UMi9xHTo"}],"size":8294,"noattachment":false,"key":"/@fastify/proxy-addr/-/@fastify/proxy-addr-5.0.0-pre.fv5.1.tgz"},"_npmUser":{"name":"jsumners","email":"james.sumners@gmail.com"},"directories":{},"maintainers":[{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"eomm","email":"behemoth89@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/proxy-addr_5.0.0-pre.fv5.1_1718826335932_0.8089826996114657"},"_hasShrinkwrap":false,"publish_time":1718826336112,"_cnpm_publish_time":1718826336112,"dist-tags":{"latest":"5.1.2","next":"5.0.0"}}