diff --git a/index.js b/index.js index 86b47dc..629dd57 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const path = require('node:path') const { fileURLToPath } = require('node:url') const { statSync } = require('node:fs') -const { glob } = require('glob') +const { glob } = require('node:fs/promises') const fp = require('fastify-plugin') const send = require('@fastify/send') const encodingNegotiator = require('@fastify/accept-negotiator') @@ -139,27 +139,30 @@ async function fastifyStatic (fastify, opts) { for (let rootPath of roots) { rootPath = rootPath.split(path.win32.sep).join(path.posix.sep) !rootPath.endsWith('/') && (rootPath += '/') - const files = await glob('**/**', { - cwd: rootPath, absolute: false, follow: true, nodir: true, dot: opts.serveDotFiles, ignore: opts.globIgnore - }) - - for (let file of files) { - file = file.split(path.win32.sep).join(path.posix.sep) - const route = prefix + file - if (routes.has(route)) { - continue - } + const files = await Array.fromAsync(glob('**/**', { + cwd: rootPath, absolute: false, follow: true, nodir: true, dot: opts.serveDotFiles,ignore: opts.globIgnore + })) + + for (let file of files) + { + + file = file.split(path.win32.sep).join(path.posix.sep) + const route = prefix + file + + if (routes.has(route)) { + continue + } - routes.add(route) + routes.add(route) - setUpHeadAndGet(routeOpts, route, `/${file}`, rootPath) + setUpHeadAndGet(routeOpts, route, `/${file}`, rootPath) - const key = path.posix.basename(route) - if (indexes.has(key) && !indexDirs.has(key)) { - indexDirs.set(path.posix.dirname(route), rootPath) + const key = path.posix.basename(route) + if (indexes.has(key) && !indexDirs.has(key)) { + indexDirs.set(path.posix.dirname(route), rootPath) + } } - } } for (const [dirname, rootPath] of indexDirs.entries()) { diff --git a/package.json b/package.json index 011daf5..1d5e6a2 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,7 @@ "@fastify/send": "^4.0.0", "content-disposition": "^0.5.4", "fastify-plugin": "^5.0.0", - "fastq": "^1.17.1", - "glob": "^11.0.0" + "fastq": "^1.17.1" }, "devDependencies": { "@fastify/compress": "^8.0.0",