@@ -3669,3 +3669,77 @@ test('register /static/ with custom log level', async t => {
36693669 t . assert . deepStrictEqual ( response2 . status , 304 )
36703670 } )
36713671} )
3672+
3673+ test ( 'register with wildcard false and globIgnore' , async t => {
3674+ t . plan ( 5 )
3675+
3676+ const indexContent = fs
3677+ . readFileSync ( './test/static-filtered/index.html' )
3678+ . toString ( 'utf8' )
3679+
3680+ const deepContent = fs
3681+ . readFileSync ( './test/static-filtered/deep/path/to/baz.html' )
3682+ . toString ( 'utf8' )
3683+
3684+ const pluginOptions = {
3685+ root : path . join ( __dirname , '/static-filtered' ) ,
3686+ wildcard : false ,
3687+ globIgnore : [ '**/*.private' ]
3688+ }
3689+ const fastify = Fastify ( )
3690+ fastify . register ( fastifyStatic , pluginOptions )
3691+
3692+ t . after ( ( ) => fastify . close ( ) )
3693+
3694+ await fastify . listen ( { port : 0 } )
3695+
3696+ fastify . server . unref ( )
3697+
3698+ await t . test ( '/index.html' , async t => {
3699+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
3700+
3701+ const response = await fetch ( 'http://localhost:' + fastify . server . address ( ) . port + '/index.html' )
3702+ t . assert . ok ( response . ok )
3703+ t . assert . deepStrictEqual ( response . status , 200 )
3704+ t . assert . deepStrictEqual ( await response . text ( ) , indexContent )
3705+ genericResponseChecks ( t , response )
3706+ } )
3707+
3708+ await t . test ( '/bar.private' , async t => {
3709+ t . plan ( 2 )
3710+
3711+ const response = await fetch ( 'http://localhost:' + fastify . server . address ( ) . port + '/bar.private' )
3712+ t . assert . ok ( ! response . ok )
3713+ t . assert . deepStrictEqual ( response . status , 404 )
3714+ await response . text ( )
3715+ } )
3716+
3717+ await t . test ( '/' , async ( t ) => {
3718+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
3719+
3720+ const response = await fetch ( 'http://localhost:' + fastify . server . address ( ) . port )
3721+ t . assert . ok ( response . ok )
3722+ t . assert . deepStrictEqual ( response . status , 200 )
3723+ t . assert . deepStrictEqual ( await response . text ( ) , indexContent )
3724+ genericResponseChecks ( t , response )
3725+ } )
3726+
3727+ await t . test ( '/deep/path/to/baz.html' , async ( t ) => {
3728+ t . plan ( 3 + GENERIC_RESPONSE_CHECK_COUNT )
3729+
3730+ const response = await fetch ( 'http://localhost:' + fastify . server . address ( ) . port + '/deep/path/to/baz.html' )
3731+ t . assert . ok ( response . ok )
3732+ t . assert . deepStrictEqual ( response . status , 200 )
3733+ t . assert . deepStrictEqual ( await response . text ( ) , deepContent )
3734+ genericResponseChecks ( t , response )
3735+ } )
3736+
3737+ await t . test ( '/deep/path/to/baz.private' , async ( t ) => {
3738+ t . plan ( 2 )
3739+
3740+ const response = await fetch ( 'http://localhost:' + fastify . server . address ( ) . port + '/deep/path/to/baz.private' )
3741+ t . assert . ok ( ! response . ok )
3742+ t . assert . deepStrictEqual ( response . status , 404 )
3743+ await response . text ( )
3744+ } )
3745+ } )
0 commit comments