@@ -19,7 +19,7 @@ send.mime.default_type = 'application/octet-stream'
19
19
20
20
async function fastifyStatic ( fastify , opts ) {
21
21
opts . root = normalizeRoot ( opts . root )
22
- checkRootPathForErrors ( fastify , opts . root )
22
+ checkRootPathForErrors ( fastify , opts . root , opts . getPathNotFoundWarning ) ;
23
23
24
24
const setHeaders = opts . setHeaders
25
25
if ( setHeaders !== undefined && typeof setHeaders !== 'function' ) {
@@ -417,7 +417,7 @@ function normalizeRoot (root) {
417
417
return root
418
418
}
419
419
420
- function checkRootPathForErrors ( fastify , rootPath ) {
420
+ function checkRootPathForErrors ( fastify , rootPath , getPathNotFoundWarning ) {
421
421
if ( rootPath === undefined ) {
422
422
throw new Error ( '"root" option is required' )
423
423
}
@@ -434,18 +434,18 @@ function checkRootPathForErrors (fastify, rootPath) {
434
434
}
435
435
436
436
// check each path and fail at first invalid
437
- rootPath . map ( ( path ) => checkPath ( fastify , path ) )
437
+ rootPath . map ( ( path ) => checkPath ( fastify , path , getPathNotFoundWarning ) )
438
438
return
439
439
}
440
440
441
441
if ( typeof rootPath === 'string' ) {
442
- return checkPath ( fastify , rootPath )
442
+ return checkPath ( fastify , rootPath , getPathNotFoundWarning )
443
443
}
444
444
445
445
throw new Error ( '"root" option must be a string or array of strings' )
446
446
}
447
447
448
- function checkPath ( fastify , rootPath ) {
448
+ function checkPath ( fastify , rootPath , getPathNotFoundWarning ) {
449
449
if ( typeof rootPath !== 'string' ) {
450
450
throw new TypeError ( '"root" option must be a string' )
451
451
}
@@ -459,7 +459,11 @@ function checkPath (fastify, rootPath) {
459
459
pathStat = statSync ( rootPath )
460
460
} catch ( e ) {
461
461
if ( e . code === 'ENOENT' ) {
462
- fastify . log . warn ( `"root" path "${ rootPath } " must exist` )
462
+ const warningMessage =
463
+ getPathNotFoundWarning
464
+ ? getPathNotFoundWarning ( rootPath )
465
+ : `"root" path "${ rootPath } " must exist`
466
+ fastify . log . warn ( warningMessage )
463
467
return
464
468
}
465
469
0 commit comments