diff --git a/types/index.d.ts b/types/index.d.ts index 7f19cbd..1a13fc4 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4,6 +4,7 @@ import { FastifyPluginCallback, FastifyReply, FastifyRequest, + HTTPMethods, preHandlerHookHandler, preValidationHookHandler, RawServerBase, @@ -99,7 +100,12 @@ interface FastifyHttpProxyWebsocketOptionsDisabled { type FastifyHttpProxy = FastifyPluginCallback< fastifyHttpProxy.FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled) -> +> & { + defaultRoutes: string[]; + defaultHttpMethods: HTTPMethods[]; + fastifyHttpProxy: FastifyHttpProxy; + default: FastifyHttpProxy; +} declare namespace fastifyHttpProxy { type ProxyPreRewriteHookHandler = ( @@ -130,11 +136,13 @@ declare namespace fastifyHttpProxy { wsClientOptions?: ClientOptions & { queryString?: { [key: string]: unknown } | QueryStringFunction; }; wsServerOptions?: ServerOptions; routes?: string[]; - httpMethods?: string[]; + httpMethods?: HTTPMethods | HTTPMethods[]; constraints?: { [name: string]: any }; internalRewriteLocationHeader?: boolean; } + export const defaultRoutes: string[] + export const defaultHttpMethods: HTTPMethods[] export const fastifyHttpProxy: FastifyHttpProxy export { fastifyHttpProxy as default } } diff --git a/types/index.tst.ts b/types/index.tst.ts index e8667f6..02367f8 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -1,4 +1,5 @@ import fastify, { + type HTTPMethods, RawReplyDefaultExpression, RawRequestDefaultExpression, type FastifyRequest, @@ -7,7 +8,7 @@ import fastify, { } from 'fastify' import { expect } from 'tstyche' import { type FastifyReplyFromHooks } from '@fastify/reply-from' -import fastifyHttpProxy from '..' +import fastifyHttpProxy, { defaultRoutes, defaultHttpMethods } from '..' const app = fastify() @@ -183,3 +184,13 @@ app.register(fastifyHttpProxy, { websocket: false, internalRewriteLocationHeader: 'NON_BOOLEAN_VALUE' }) + +app.register(fastifyHttpProxy, { + upstream: 'http://origin.asd', + httpMethods: 'GET' +}) + +expect(fastifyHttpProxy.defaultRoutes).type.toBe() +expect(fastifyHttpProxy.defaultHttpMethods).type.toBe() +expect(defaultRoutes).type.toBe() +expect(defaultHttpMethods).type.toBe()