Skip to content
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
12 changes: 10 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
FastifyPluginCallback,
FastifyReply,
FastifyRequest,
HTTPMethods,
preHandlerHookHandler,
preValidationHookHandler,
RawServerBase,
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 }
}
Expand Down
13 changes: 12 additions & 1 deletion types/index.tst.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fastify, {
type HTTPMethods,
RawReplyDefaultExpression,
RawRequestDefaultExpression,
type FastifyRequest,
Expand All @@ -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()

Expand Down Expand Up @@ -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<string[]>()
expect(fastifyHttpProxy.defaultHttpMethods).type.toBe<HTTPMethods[]>()
expect(defaultRoutes).type.toBe<string[]>()
expect(defaultHttpMethods).type.toBe<HTTPMethods[]>()
Loading