Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 089df88

Browse files
authored
nodenext compatibility (#71)
* nodenext compatibility * patch pem version, as latest pem is not released * revert back to loading pem from npm
1 parent 6c06756 commit 089df88

File tree

4 files changed

+72
-48
lines changed

4 files changed

+72
-48
lines changed

index.d.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"version": "2.1.0",
44
"description": "Forward your HTTP request to another server.",
55
"main": "index.js",
6-
"types": "index.d.ts",
6+
"types": "types/index.d.ts",
77
"scripts": {
8-
"lint": "npx standard",
9-
"test": "nyc mocha test/*.test.js",
8+
"lint": "standard",
9+
"test": "npm run test:unit && npm run test:typescript",
10+
"test:unit": "nyc mocha test/*.test.js",
11+
"test:typescript": "tsd",
1012
"bench": "( node benchmark/service.js & node benchmark/fast-proxy-0http-gateway.js & (sleep 5 && wrk -t8 -c8 -d30s http://127.0.0.1:8080/service/hi) )"
1113
},
1214
"repository": {
@@ -22,7 +24,7 @@
2224
"files": [
2325
"LICENSE",
2426
"README.md",
25-
"index.d.ts",
27+
"types/index.d.ts",
2628
"index.js",
2729
"lib/"
2830
],
@@ -33,6 +35,7 @@
3335
},
3436
"homepage": "https://github.com/fastify/fast-proxy",
3537
"devDependencies": {
38+
"@types/node": "^18.11.10",
3639
"0http": "^3.1.1",
3740
"body-parser": "^1.19.0",
3841
"chai": "^4.3.4",
@@ -45,7 +48,8 @@
4548
"restana": "^4.9.1",
4649
"self-cert": "^2.0.0",
4750
"standard": "^17.0.0",
48-
"supertest": "^6.1.6"
51+
"supertest": "^6.1.6",
52+
"tsd": "^0.25.0"
4953
},
5054
"dependencies": {
5155
"end-of-stream": "^1.4.4",

types/index.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as Http from 'http';
2+
import * as Https from 'https';
3+
import * as Undici from 'undici';
4+
5+
type Stream = ReadableStream | WritableStream
6+
7+
type FastProxy = (options?: fastProxy.FastProxyOptions) => {
8+
proxy(
9+
originReq: Http.IncomingMessage,
10+
originRes: Http.ServerResponse,
11+
source: string,
12+
opts?: {
13+
base?: string;
14+
onResponse?(req: Http.IncomingMessage, res: Http.ServerResponse, stream: Stream): void;
15+
rewriteRequestHeaders?(req: Http.IncomingMessage, headers: Http.IncomingHttpHeaders): Http.IncomingHttpHeaders;
16+
rewriteHeaders?(headers: Http.OutgoingHttpHeaders): Http.OutgoingHttpHeaders;
17+
request?: Http.RequestOptions;
18+
queryString?: string;
19+
}
20+
): void;
21+
close(): void;
22+
}
23+
24+
declare namespace fastProxy {
25+
interface QueryStringModule {
26+
stringify(value: any): string;
27+
parse(value: string): any;
28+
}
29+
30+
export interface FastProxyOptions {
31+
base?: string;
32+
http2?: boolean;
33+
undici?: Undici.Pool.Options;
34+
cacheURLs?: number;
35+
requests?: {
36+
http?: Http.Agent,
37+
https?: Https.Agent
38+
};
39+
keepAliveMsecs?: number;
40+
maxSockets?: number;
41+
rejectUnauthorized?: boolean;
42+
queryString?: QueryStringModule;
43+
}
44+
45+
export const fastProxy: FastProxy
46+
export { fastProxy as default }
47+
}
48+
49+
declare function fastProxy(...params: Parameters<FastProxy>): ReturnType<FastProxy>
50+
export = fastProxy

types/index.test-d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fastProxy, { fastProxy as fastProxyNamed} from '..'
2+
import { expectAssignable, expectType } from 'tsd'
3+
4+
const proxy = fastProxy({
5+
base: 'http://127.0.0.1:3000'
6+
})
7+
fastProxyNamed({
8+
base: 'http://127.0.0.1:3000'
9+
})
10+
11+
expectType<typeof fastProxyNamed>(fastProxy)
12+
expectType<() => void>(proxy.close)
13+
expectAssignable<Function>(proxy.proxy)

0 commit comments

Comments
 (0)