From 3511fcc512d9da1930208061f46e657202f3ccd5 Mon Sep 17 00:00:00 2001 From: arcaniussainey Date: Mon, 24 Nov 2025 20:33:30 -0500 Subject: [PATCH] Refactored to match original codestyle --- index.js | 37 ++++++++++++++++++++----------------- package.json | 5 ++--- 2 files changed, 22 insertions(+), 20 deletions(-) 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 cb7fa66..1d5e6a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fastify/static", - "version": "8.2.0", + "version": "8.3.0", "description": "Plugin for serving static files as fast as possible.", "main": "index.js", "type": "commonjs", @@ -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",