Skip to content

Commit ca8abf8

Browse files
authored
nodenext compatibility (#279)
1 parent c68564f commit ca8abf8

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed

index.d.ts

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

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function generateRewritePrefix (prefix = '', opts) {
185185
return rewritePrefix
186186
}
187187

188-
async function httpProxy (fastify, opts) {
188+
async function fastifyHttpProxy (fastify, opts) {
189189
if (!opts.upstream && !(opts.upstream === '' && opts.replyOptions && typeof opts.replyOptions.getUpstream === 'function')) {
190190
throw new Error('upstream must be specified')
191191
}
@@ -261,11 +261,11 @@ async function httpProxy (fastify, opts) {
261261
}
262262
}
263263

264-
httpProxy[Symbol.for('plugin-meta')] = {
264+
fastifyHttpProxy[Symbol.for('plugin-meta')] = {
265265
fastify: '4.x',
266266
name: '@fastify/http-proxy'
267267
}
268268

269-
module.exports = httpProxy
270-
module.exports.default = httpProxy
271-
module.exports.fastifyHttpProxy = httpProxy
269+
module.exports = fastifyHttpProxy
270+
module.exports.default = fastifyHttpProxy
271+
module.exports.fastifyHttpProxy = fastifyHttpProxy

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "8.2.3",
44
"description": "proxy http requests, for Fastify",
55
"main": "index.js",
6-
"types": "index.d.ts",
6+
"types": "types/index.d.ts",
77
"scripts": {
88
"lint": "standard | snazzy",
99
"lint:fix": "standard --fix | snazzy",

types/index.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference types='node' />
2+
3+
import { FastifyPluginCallback, preHandlerHookHandler } from 'fastify';
4+
5+
import {
6+
FastifyReplyFromOptions,
7+
FastifyReplyFromHooks,
8+
} from '@fastify/reply-from';
9+
10+
import { ClientOptions, ServerOptions } from 'ws';
11+
12+
type FastifyHttpProxy = FastifyPluginCallback<fastifyHttpProxy.FastifyHttpProxyOptions>;
13+
14+
declare namespace fastifyHttpProxy {
15+
export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
16+
upstream: string;
17+
prefix?: string;
18+
rewritePrefix?: string;
19+
proxyPayloads?: boolean;
20+
preHandler?: preHandlerHookHandler;
21+
beforeHandler?: preHandlerHookHandler;
22+
config?: Object;
23+
replyOptions?: FastifyReplyFromHooks;
24+
websocket?: boolean;
25+
wsClientOptions?: ClientOptions;
26+
wsServerOptions?: ServerOptions;
27+
httpMethods?: string[];
28+
constraints?: { [name: string]: any };
29+
}
30+
31+
export const fastifyHttpProxy: FastifyHttpProxy
32+
export { fastifyHttpProxy as default }
33+
}
34+
35+
declare function fastifyHttpProxy(...params: Parameters<FastifyHttpProxy>): ReturnType<FastifyHttpProxy>
36+
export = fastifyHttpProxy

test/types/index.test-d.ts renamed to types/index.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from 'fastify';
22
import { expectError, expectType } from 'tsd';
3-
import fastifyHttpProxy from '../..';
3+
import fastifyHttpProxy from '..';
44

55
const app = fastify();
66

0 commit comments

Comments
 (0)