source: trip-planner-front/node_modules/proxy-addr/README.md@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.0 KB
Line 
1# proxy-addr
2
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 request
10
11## Install
12
13This is a [Node.js](https://nodejs.org/en/) module available through the
14[npm registry](https://www.npmjs.com/). Installation is done using the
15[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
16
17```sh
18$ npm install proxy-addr
19```
20
21## API
22
23```js
24var 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 trust
32the address, `false` if you don't. The closest untrusted address is
33returned.
34
35```js
36proxyaddr(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 an
41array of trusted addresses, as plain IP addresses, CIDR-formatted
42strings, or IP/netmask strings.
43
44```js
45proxyaddr(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 normalized
51automatically (i.e. `fe80::00ed:1` equals `fe80:0:0:0:0:0:ed:1`).
52
53```js
54proxyaddr(req, '::1')
55proxyaddr(req, ['::1/128', 'fe80::/10'])
56```
57
58This module will automatically work with IPv4-mapped IPv6 addresses
59as well to support node.js in IPv6-only mode. This means that you do
60not have to specify both `::ffff:a00:1` and `10.0.0.1`.
61
62As a convenience, this module also takes certain pre-defined names
63in addition to IP addresses, which expand into IP addresses:
64
65```js
66proxyaddr(req, 'loopback')
67proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])
68```
69
70 * `loopback`: IPv4 and IPv6 loopback addresses (like `::1` and
71 `127.0.0.1`).
72 * `linklocal`: IPv4 and IPv6 link-local addresses (like
73 `fe80::1:1:1:1` and `169.254.0.1`).
74 * `uniquelocal`: IPv4 private addresses and IPv6 unique-local
75 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 each
78address to determine if it is a trusted address. The function is
79given two arguments: `addr` and `i`, where `addr` is a string of
80the address to check and `i` is a number that represents the distance
81from the socket address.
82
83### proxyaddr.all(req, [trust])
84
85Return all the addresses of the request, optionally stopping at the
86first untrusted. This array is ordered from closest to furthest
87(i.e. `arr[0] === req.connection.remoteAddress`).
88
89```js
90proxyaddr.all(req)
91```
92
93The optional `trust` argument takes the same arguments as `trust`
94does in `proxyaddr(req, trust)`.
95
96```js
97proxyaddr.all(req, 'loopback')
98```
99
100### proxyaddr.compile(val)
101
102Compiles argument `val` into a `trust` function. This function takes
103the same arguments as `trust` does in `proxyaddr(req, trust)` and
104returns a function suitable for `proxyaddr(req, trust)`.
105
106```js
107var 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 trusted
113configuration and pass that to `proxyaddr(req, trust)` for each request.
114
115## Testing
116
117```sh
118$ npm test
119```
120
121## Benchmarks
122
123```sh
124$ npm run-script bench
125```
126
127## License
128
129[MIT](LICENSE)
130
131[ci-image]: https://badgen.net/github/checks/jshttp/proxy-addr/master?label=ci
132[ci-url]: https://github.com/jshttp/proxy-addr/actions?query=workflow%3Aci
133[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/proxy-addr/master
134[coveralls-url]: https://coveralls.io/r/jshttp/proxy-addr?branch=master
135[node-image]: https://badgen.net/npm/node/proxy-addr
136[node-url]: https://nodejs.org/en/download
137[npm-downloads-image]: https://badgen.net/npm/dm/proxy-addr
138[npm-url]: https://npmjs.org/package/proxy-addr
139[npm-version-image]: https://badgen.net/npm/v/proxy-addr
Note: See TracBrowser for help on using the repository browser.