Skip to content

Commit

Permalink
add url type (#398)
Browse files Browse the repository at this point in the history
* add url type

* add type tests

* lint
  • Loading branch information
gurgunday authored Aug 31, 2023
1 parent cdf3d70 commit 426f3be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ expectError<FastifyStaticOptions>({
}
})

expectAssignable<FastifyStaticOptions>({
root: ['']
})

expectAssignable<FastifyStaticOptions>({
root: new URL('')
})

expectAssignable<FastifyStaticOptions>({
root: [new URL('')]
})

appWithImplicitHttp
.register(fastifyStatic, options)
.after(() => {
Expand Down Expand Up @@ -170,6 +182,16 @@ noIndexApp
})
})

options.root = new URL('')

const URLRootApp = fastify()
URLRootApp.register(fastifyStatic, options)
.after(() => {
URLRootApp.get('/', (request, reply) => {
reply.send('<h1>fastify-static</h1>')
})
})

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

Expand Down

0 comments on commit 426f3be

Please sign in to comment.