diff --git a/index.d.ts b/index.d.ts
deleted file mode 100644
index e8bbadf..0000000
--- a/index.d.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-///
-
-import { FastifyPluginCallback, preHandlerHookHandler } from 'fastify';
-
-import {
- FastifyReplyFromOptions,
- FastifyReplyFromHooks,
-} from '@fastify/reply-from';
-
-import { ClientOptions, ServerOptions } from 'ws';
-
-export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
- upstream: string;
- prefix?: string;
- rewritePrefix?: string;
- proxyPayloads?: boolean;
- preHandler?: preHandlerHookHandler;
- beforeHandler?: preHandlerHookHandler;
- config?: Object;
- replyOptions?: FastifyReplyFromHooks;
- websocket?: boolean;
- wsClientOptions?: ClientOptions;
- wsServerOptions?: ServerOptions;
- httpMethods?: string[];
- constraints?: { [name: string]: any };
-}
-
-export const fastifyHttpProxy: FastifyPluginCallback;
-export default fastifyHttpProxy;
diff --git a/index.js b/index.js
index 99f9da8..f10198d 100644
--- a/index.js
+++ b/index.js
@@ -185,7 +185,7 @@ function generateRewritePrefix (prefix = '', opts) {
return rewritePrefix
}
-async function httpProxy (fastify, opts) {
+async function fastifyHttpProxy (fastify, opts) {
if (!opts.upstream && !(opts.upstream === '' && opts.replyOptions && typeof opts.replyOptions.getUpstream === 'function')) {
throw new Error('upstream must be specified')
}
@@ -261,11 +261,11 @@ async function httpProxy (fastify, opts) {
}
}
-httpProxy[Symbol.for('plugin-meta')] = {
+fastifyHttpProxy[Symbol.for('plugin-meta')] = {
fastify: '4.x',
name: '@fastify/http-proxy'
}
-module.exports = httpProxy
-module.exports.default = httpProxy
-module.exports.fastifyHttpProxy = httpProxy
+module.exports = fastifyHttpProxy
+module.exports.default = fastifyHttpProxy
+module.exports.fastifyHttpProxy = fastifyHttpProxy
diff --git a/package.json b/package.json
index 9d477c5..1ea3777 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"version": "8.2.3",
"description": "proxy http requests, for Fastify",
"main": "index.js",
- "types": "index.d.ts",
+ "types": "types/index.d.ts",
"scripts": {
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
diff --git a/types/index.d.ts b/types/index.d.ts
new file mode 100644
index 0000000..631446b
--- /dev/null
+++ b/types/index.d.ts
@@ -0,0 +1,36 @@
+///
+
+import { FastifyPluginCallback, preHandlerHookHandler } from 'fastify';
+
+import {
+ FastifyReplyFromOptions,
+ FastifyReplyFromHooks,
+} from '@fastify/reply-from';
+
+import { ClientOptions, ServerOptions } from 'ws';
+
+type FastifyHttpProxy = FastifyPluginCallback;
+
+declare namespace fastifyHttpProxy {
+ export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
+ upstream: string;
+ prefix?: string;
+ rewritePrefix?: string;
+ proxyPayloads?: boolean;
+ preHandler?: preHandlerHookHandler;
+ beforeHandler?: preHandlerHookHandler;
+ config?: Object;
+ replyOptions?: FastifyReplyFromHooks;
+ websocket?: boolean;
+ wsClientOptions?: ClientOptions;
+ wsServerOptions?: ServerOptions;
+ httpMethods?: string[];
+ constraints?: { [name: string]: any };
+ }
+
+ export const fastifyHttpProxy: FastifyHttpProxy
+ export { fastifyHttpProxy as default }
+}
+
+declare function fastifyHttpProxy(...params: Parameters): ReturnType
+export = fastifyHttpProxy
diff --git a/test/types/index.test-d.ts b/types/index.test-d.ts
similarity index 97%
rename from test/types/index.test-d.ts
rename to types/index.test-d.ts
index 99ed637..0e87337 100644
--- a/test/types/index.test-d.ts
+++ b/types/index.test-d.ts
@@ -1,6 +1,6 @@
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from 'fastify';
import { expectError, expectType } from 'tsd';
-import fastifyHttpProxy from '../..';
+import fastifyHttpProxy from '..';
const app = fastify();