diff --git a/index.js b/index.js index eba832fa..76ce3b39 100644 --- a/index.js +++ b/index.js @@ -272,7 +272,7 @@ async function fastifyStatic (fastify, opts) { } const errorHandler = (error, request, reply) => { - if (error && error.code === 'ERR_STREAM_PREMATURE_CLOSE') { + if (error?.code === 'ERR_STREAM_PREMATURE_CLOSE') { reply.request.raw.destroy() return } diff --git a/lib/dirList.js b/lib/dirList.js index 7aec88b8..0e61ac88 100644 --- a/lib/dirList.js +++ b/lib/dirList.js @@ -16,7 +16,7 @@ const dirList = { const entries = { dirs: [], files: [] } let files = await fs.readdir(dir) if (dotfiles === 'deny' || dotfiles === 'ignore') { - files = files.filter(f => f.charAt(0) !== '.') + files = files.filter(file => file.charAt(0) !== '.') } if (files.length < 1) { return entries @@ -92,6 +92,7 @@ const dirList = { entries.dirs.sort((a, b) => a.name.localeCompare(b.name)) entries.files.sort((a, b) => a.name.localeCompare(b.name)) + return entries }, @@ -141,7 +142,7 @@ const dirList = { * @return {ListFile} */ htmlInfo: function (entry, route, prefix, options) { - if (options.names && options.names.includes(path.basename(route))) { + if (options.names?.includes(path.basename(route))) { route = path.normalize(path.join(route, '..')) } return { @@ -159,12 +160,9 @@ const dirList = { * @return {boolean} */ handle: function (route, options) { - if (!options.names) { - return false - } - return options.names.includes(path.basename(route)) || + return options.names?.includes(path.basename(route)) || // match trailing slash - (options.names.includes('/') && route[route.length - 1] === '/') + ((options.names?.includes('/') && route[route.length - 1] === '/') ?? false) }, /**