From cc11dfd3b708fbe0ec5314ae2ff96c190242f3e8 Mon Sep 17 00:00:00 2001 From: Abdul karim mia Date: Mon, 23 Nov 2026 03:21:34 +0530 Subject: [PATCH] types: support single HTTPMethods string and export defaults Signed-off-by: Abdul karim mia --- types/index.d.ts | 12 ++++++++++-- types/index.tst.ts | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 7fd048a..8063a40 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4,6 +4,7 @@ import { FastifyPluginCallback, FastifyReply, FastifyRequest, + HTTPMethods, preHandlerHookHandler, preValidationHookHandler, RawServerBase, @@ -81,7 +82,12 @@ interface FastifyHttpProxyWebsocketOptionsDisabled { type FastifyHttpProxy = FastifyPluginCallback< fastifyHttpProxy.FastifyHttpProxyOptions & (FastifyHttpProxyWebsocketOptionsEnabled | FastifyHttpProxyWebsocketOptionsDisabled) -> +> & { + defaultRoutes: string[]; + defaultHttpMethods: HTTPMethods[]; + fastifyHttpProxy: FastifyHttpProxy; + default: FastifyHttpProxy; +} declare namespace fastifyHttpProxy { type ProxyPreRewriteHookHandler = ( @@ -112,11 +118,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 4946f9e..3be4753 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() @@ -180,3 +181,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()