From 426f3be25a866376a4a8beb858005a0063704c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Thu, 31 Aug 2023 14:58:32 +0300 Subject: [PATCH] add url type (#398) * add url type * add type tests * lint --- types/index.d.ts | 2 +- types/index.test-d.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index c352556..963bae0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -77,7 +77,7 @@ declare namespace fastifyStatic { } export interface FastifyStaticOptions extends SendOptions { - root: string | string[]; + root: string | string[] | URL | URL[]; prefix?: string; prefixAvoidTrailingSlash?: boolean; serve?: boolean; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 883a878..c370ebf 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -97,6 +97,18 @@ expectError({ } }) +expectAssignable({ + root: [''] +}) + +expectAssignable({ + root: new URL('') +}) + +expectAssignable({ + root: [new URL('')] +}) + appWithImplicitHttp .register(fastifyStatic, options) .after(() => { @@ -170,6 +182,16 @@ noIndexApp }) }) +options.root = new URL('') + +const URLRootApp = fastify() +URLRootApp.register(fastifyStatic, options) + .after(() => { + URLRootApp.get('/', (request, reply) => { + reply.send('

fastify-static

') + }) + }) + const defaultIndexApp = fastify() options.index = 'index.html'