opusdev/vector-similarity-api
1
1# proxy-addr2 3[![NPM Version][npm-version-image]][npm-url]4[![NPM Downloads][npm-downloads-image]][npm-url]5[![Node.js Version][node-image]][node-url]6[![Build Status][ci-image]][ci-url]7[![Test Coverage][coveralls-image]][coveralls-url]8 9Determine address of proxied request10 11## Install12 13This is a [Node.js](https://nodejs.org/en/) module available through the14[npm registry](https://www.npmjs.com/). Installation is done using the15[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):16 17```sh18$ npm install proxy-addr19```20 21## API22 23```js24var proxyaddr = require('proxy-addr')25```26 27### proxyaddr(req, trust)28 29Return the address of the request, using the given `trust` parameter.30 31The `trust` argument is a function that returns `true` if you trust32the address, `false` if you don't. The closest untrusted address is33returned.34 35```js36proxyaddr(req, function (addr) { return addr === '127.0.0.1' })37proxyaddr(req, function (addr, i) { return i < 1 })38```39 40The `trust` arugment may also be a single IP address string or an41array of trusted addresses, as plain IP addresses, CIDR-formatted42strings, or IP/netmask strings.43 44```js45proxyaddr(req, '127.0.0.1')46proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])47proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])48```49 50This module also supports IPv6. Your IPv6 addresses will be normalized51automatically (i.e. `fe80::00ed:1` equals `fe80:0:0:0:0:0:ed:1`).52 53```js54proxyaddr(req, '::1')55proxyaddr(req, ['::1/128', 'fe80::/10'])56```57 58This module will automatically work with IPv4-mapped IPv6 addresses59as well to support node.js in IPv6-only mode. This means that you do60not have to specify both `::ffff:a00:1` and `10.0.0.1`.61 62As a convenience, this module also takes certain pre-defined names63in addition to IP addresses, which expand into IP addresses:64 65```js66proxyaddr(req, 'loopback')67proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])68```69 70 * `loopback`: IPv4 and IPv6 loopback addresses (like `::1` and71 `127.0.0.1`).72 * `linklocal`: IPv4 and IPv6 link-local addresses (like73 `fe80::1:1:1:1` and `169.254.0.1`).74 * `uniquelocal`: IPv4 private addresses and IPv6 unique-local75 addresses (like `fc00:ac:1ab5:fff::1` and `192.168.0.1`).76 77When `trust` is specified as a function, it will be called for each78address to determine if it is a trusted address. The function is79given two arguments: `addr` and `i`, where `addr` is a string of80the address to check and `i` is a number that represents the distance81from the socket address.82 83### proxyaddr.all(req, [trust])84 85Return all the addresses of the request, optionally stopping at the86first untrusted. This array is ordered from closest to furthest87(i.e. `arr[0] === req.connection.remoteAddress`).88 89```js90proxyaddr.all(req)91```92 93The optional `trust` argument takes the same arguments as `trust`94does in `proxyaddr(req, trust)`.95 96```js97proxyaddr.all(req, 'loopback')98```99 100### proxyaddr.compile(val)101 102Compiles argument `val` into a `trust` function. This function takes103the same arguments as `trust` does in `proxyaddr(req, trust)` and104returns a function suitable for `proxyaddr(req, trust)`.105 106```js107var trust = proxyaddr.compile('loopback')108var addr = proxyaddr(req, trust)109```110 111This function is meant to be optimized for use against every request.112It is recommend to compile a trust function up-front for the trusted113configuration and pass that to `proxyaddr(req, trust)` for each request.114 115## Testing116 117```sh118$ npm test119```120 121## Benchmarks122 123```sh124$ npm run-script bench125```126 127## License128 129[MIT](LICENSE)130 131[ci-image]: https://badgen.net/github/checks/jshttp/proxy-addr/master?label=ci132[ci-url]: https://github.com/jshttp/proxy-addr/actions?query=workflow%3Aci133[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/proxy-addr/master134[coveralls-url]: https://coveralls.io/r/jshttp/proxy-addr?branch=master135[node-image]: https://badgen.net/npm/node/proxy-addr136[node-url]: https://nodejs.org/en/download137[npm-downloads-image]: https://badgen.net/npm/dm/proxy-addr138[npm-url]: https://npmjs.org/package/proxy-addr139[npm-version-image]: https://badgen.net/npm/v/proxy-addr140 