Skip to content

Commit 87efcff

Browse files
authored
nodenext compatiblity (#42)
* nodenext compatibility * enable lint in wf
1 parent 588916d commit 87efcff

File tree

6 files changed

+58
-7
lines changed

6 files changed

+58
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ jobs:
1515
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
1616
with:
1717
license-check: true
18+
lint: true

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414

1515
module.exports = proxyaddr
16+
module.exports.default = proxyaddr
17+
module.exports.proxyaddr = proxyaddr
1618
module.exports.all = alladdrs
1719
module.exports.compile = compile
1820

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "@fastify/proxy-addr",
33
"description": "Determine address of proxied request",
44
"version": "4.0.0",
5+
"main": "index.js",
6+
"types": "types/index.d.ts",
57
"author": "Douglas Christopher Wilson <[email protected]>",
68
"license": "MIT",
79
"keywords": [
@@ -22,18 +24,18 @@
2224
"ipaddr.js": "^2.0.0"
2325
},
2426
"devDependencies": {
27+
"@types/node": "^18.11.11",
2528
"beautify-benchmark": "0.2.4",
2629
"benchmark": "2.1.4",
2730
"standard": "^17.0.0",
28-
"tap": "^16.0.0"
31+
"tap": "^16.0.0",
32+
"tsd": "^0.25.0"
2933
},
30-
"files": [
31-
"LICENSE",
32-
"README.md",
33-
"index.js"
34-
],
3534
"scripts": {
3635
"bench": "node benchmark/index.js",
37-
"test": "standard && tap"
36+
"lint": "standard",
37+
"test": "npm run test:unit && npm run test:typescript",
38+
"test:typescript": "tsd",
39+
"test:unit": "tap"
3840
}
3941
}

types/index.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference types="node" />
2+
3+
import { IncomingMessage } from 'http';
4+
5+
type FastifyProxyAddr = typeof proxyaddr
6+
7+
declare function proxyaddr(req: IncomingMessage, trust: proxyaddr.Address | proxyaddr.Address[] | ((addr: string, i: number) => boolean)): string;
8+
9+
declare namespace proxyaddr {
10+
export function all(req: IncomingMessage, trust?: Address | Address[] | ((addr: string, i: number) => boolean)): string[];
11+
export function compile(val: Address | Address[]): (addr: string, i: number) => boolean;
12+
13+
export type Address = 'loopback' | 'linklocal' | 'uniquelocal' | string;
14+
15+
export const proxyAddr: FastifyProxyAddr
16+
export { proxyAddr as default }
17+
}
18+
export = proxyaddr;

types/index.test-d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import proxyaddr from '..';
2+
import { createServer } from 'http';
3+
4+
createServer(req => {
5+
// $ExpectType string
6+
proxyaddr(req, addr => addr === '127.0.0.1');
7+
proxyaddr(req, (addr, i) => i < 1);
8+
9+
proxyaddr(req, '127.0.0.1');
10+
proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8']);
11+
proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0']);
12+
13+
proxyaddr(req, '::1');
14+
proxyaddr(req, ['::1/128', 'fe80::/10']);
15+
16+
proxyaddr(req, 'loopback');
17+
proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64']);
18+
19+
// $ExpectType string[]
20+
proxyaddr.all(req);
21+
proxyaddr.all(req, 'loopback');
22+
23+
const trust = proxyaddr.compile('localhost');
24+
proxyaddr.compile(['localhost']);
25+
trust; // $ExpectType (addr: string, i: number) => boolean
26+
proxyaddr(req, trust);
27+
});

0 commit comments

Comments
 (0)