File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ send.mime.default_type = 'application/octet-stream'
1919
2020/** @type {import("fastify").FastifyPluginAsync<import("./types").FastifyStaticOptions> } */
2121async function fastifyStatic ( fastify , opts ) {
22- if ( opts . serve !== false ) {
22+ if ( opts . serve !== false || opts . root !== undefined ) {
2323 opts . root = normalizeRoot ( opts . root )
2424 checkRootPathForErrors ( fastify , opts . root )
2525 }
Original file line number Diff line number Diff line change @@ -1260,7 +1260,7 @@ test('maxAge option', async (t) => {
12601260} )
12611261
12621262test ( 'errors' , async ( t ) => {
1263- t . plan ( 11 )
1263+ t . plan ( 12 )
12641264
12651265 await t . test ( 'no root' , async ( t ) => {
12661266 t . plan ( 1 )
@@ -1325,6 +1325,16 @@ test('errors', async (t) => {
13251325 await t . assert . rejects ( async ( ) => await fastify . register ( fastifyStatic , pluginOptions ) )
13261326 } )
13271327
1328+ await t . test ( 'no root and serve: false' , async ( t ) => {
1329+ t . plan ( 1 )
1330+ const pluginOptions = {
1331+ serve : false ,
1332+ root : [ ]
1333+ }
1334+ const fastify = Fastify ( { logger : false } )
1335+ await t . assert . rejects ( async ( ) => await fastify . register ( fastifyStatic , pluginOptions ) )
1336+ } )
1337+
13281338 await t . test ( 'duplicate root paths are not allowed' , async ( t ) => {
13291339 t . plan ( 1 )
13301340 const pluginOptions = {
You can’t perform that action at this time.
0 commit comments