From 6d8835651451732a106820a20a8d67cdc37ead2b 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 12:31:24 +0300 Subject: [PATCH 1/3] add url type --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 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; From 985360731bba0b61298be0ca35e84ae564bbcbb0 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:37:57 +0300 Subject: [PATCH 2/3] add type tests --- types/index.test-d.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 883a878..a8ed243 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' From 2a829874bf0155b286b5f8a5ce46a96e6e6fa0cc 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:51:32 +0300 Subject: [PATCH 3/3] lint --- types/index.test-d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index a8ed243..c370ebf 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -98,15 +98,15 @@ expectError({ }) expectAssignable({ - root: [''], + root: [''] }) expectAssignable({ - root: new URL(''), + root: new URL('') }) expectAssignable({ - root: [new URL('')], + root: [new URL('')] }) appWithImplicitHttp @@ -186,11 +186,11 @@ options.root = new URL('') const URLRootApp = fastify() URLRootApp.register(fastifyStatic, options) -.after(() => { - URLRootApp.get('/', (request, reply) => { - reply.send('

fastify-static

') + .after(() => { + URLRootApp.get('/', (request, reply) => { + reply.send('

fastify-static

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