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

nodenext compatibility #71

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions index.d.ts

This file was deleted.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"version": "2.1.0",
"description": "Forward your HTTP request to another server.",
"main": "index.js",
"types": "index.d.ts",
"types": "types/index.d.ts",
"scripts": {
"lint": "npx standard",
"test": "nyc mocha test/*.test.js",
"lint": "standard",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "nyc mocha test/*.test.js",
"test:typescript": "tsd",
"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) )"
},
"repository": {
Expand All @@ -22,7 +24,7 @@
"files": [
"LICENSE",
"README.md",
"index.d.ts",
"types/index.d.ts",
"index.js",
"lib/"
],
Expand All @@ -33,6 +35,7 @@
},
"homepage": "https://github.com/fastify/fast-proxy",
"devDependencies": {
"@types/node": "^18.11.10",
"0http": "^3.1.1",
"body-parser": "^1.19.0",
"chai": "^4.3.4",
Expand All @@ -45,7 +48,8 @@
"restana": "^4.9.1",
"self-cert": "^2.0.0",
"standard": "^17.0.0",
"supertest": "^6.1.6"
"supertest": "^6.1.6",
"tsd": "^0.25.0"
},
"dependencies": {
"end-of-stream": "^1.4.4",
Expand Down
50 changes: 50 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as Http from 'http';
import * as Https from 'https';
import * as Undici from 'undici';

type Stream = ReadableStream | WritableStream

type FastProxy = (options?: fastProxy.FastProxyOptions) => {
proxy(
originReq: Http.IncomingMessage,
originRes: Http.ServerResponse,
source: string,
opts?: {
base?: string;
onResponse?(req: Http.IncomingMessage, res: Http.ServerResponse, stream: Stream): void;
rewriteRequestHeaders?(req: Http.IncomingMessage, headers: Http.IncomingHttpHeaders): Http.IncomingHttpHeaders;
rewriteHeaders?(headers: Http.OutgoingHttpHeaders): Http.OutgoingHttpHeaders;
request?: Http.RequestOptions;
queryString?: string;
}
): void;
close(): void;
}

declare namespace fastProxy {
interface QueryStringModule {
stringify(value: any): string;
parse(value: string): any;
}

export interface FastProxyOptions {
base?: string;
http2?: boolean;
undici?: Undici.Pool.Options;
cacheURLs?: number;
requests?: {
http?: Http.Agent,
https?: Https.Agent
};
keepAliveMsecs?: number;
maxSockets?: number;
rejectUnauthorized?: boolean;
queryString?: QueryStringModule;
}

export const fastProxy: FastProxy
export { fastProxy as default }
}

declare function fastProxy(...params: Parameters<FastProxy>): ReturnType<FastProxy>
export = fastProxy
13 changes: 13 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fastProxy, { fastProxy as fastProxyNamed} from '..'
import { expectAssignable, expectType } from 'tsd'

const proxy = fastProxy({
base: 'http://127.0.0.1:3000'
})
fastProxyNamed({
base: 'http://127.0.0.1:3000'
})

expectType<typeof fastProxyNamed>(fastProxy)
expectType<() => void>(proxy.close)
expectAssignable<Function>(proxy.proxy)