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'