diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b00276..5395d92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0 with: license-check: true lint: true diff --git a/index.js b/index.js index 1831e5a..d46e42b 100644 --- a/index.js +++ b/index.js @@ -282,11 +282,10 @@ async function fastifyStatic (fastify, opts) { if (opts.redirect === true) { try { reply.redirect(301, getRedirectUrl(request.raw.url)) - } catch (error) { + } /* c8 ignore start */ catch (error) { // the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack - /* istanbul ignore next */ reply.send(error) - } + } /* c8 ignore stop */ } else { // if is a directory path without a trailing slash, and has an index file, reply as if it has a trailing slash if (!pathname.endsWith('/') && findIndexFile(pathname, options.root, options.index)) { @@ -389,7 +388,7 @@ async function fastifyStatic (fastify, opts) { function serveFileHandler (req, reply) { // TODO: remove the fallback branch when bump major - /* istanbul ignore next */ + /* c8 ignore next */ const routeConfig = req.routeOptions?.config || req.routeConfig pumpSendToReply(req, reply, routeConfig.file, routeConfig.rootPath) } @@ -482,8 +481,6 @@ function getContentType (path) { } function findIndexFile (pathname, root, indexFiles = ['index.html']) { - // TODO remove istanbul ignore - /* istanbul ignore else */ if (Array.isArray(indexFiles)) { return indexFiles.find(filename => { const p = path.join(root, pathname, filename) @@ -495,7 +492,7 @@ function findIndexFile (pathname, root, indexFiles = ['index.html']) { } }) } - /* istanbul ignore next */ + /* c8 ignore next */ return false } @@ -534,15 +531,12 @@ function getRedirectUrl (url) { const parsed = new URL(url, 'http://localhost.com/') const parsedPathname = parsed.pathname return parsedPathname + (parsedPathname[parsedPathname.length - 1] !== '/' ? '/' : '') + (parsed.search || '') - } catch { + } /* c8 ignore start */ catch { // the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack - /* istanbul ignore next */ const err = new Error(`Invalid redirect URL: ${url}`) - /* istanbul ignore next */ err.statusCode = 400 - /* istanbul ignore next */ throw err - } + } /* c8 ignore stop */ } module.exports = fp(fastifyStatic, { diff --git a/package.json b/package.json index 1e1fd8d..e4bc87c 100644 --- a/package.json +++ b/package.json @@ -31,32 +31,31 @@ }, "homepage": "https://github.com/fastify/fastify-static", "dependencies": { - "@fastify/accept-negotiator": "^1.0.0", - "@fastify/send": "^2.0.0", - "content-disposition": "^0.5.3", - "fastify-plugin": "^4.0.0", - "fastq": "^1.17.0", - "glob": "^10.3.4" + "@fastify/accept-negotiator": "^1.1.0", + "@fastify/send": "^2.1.0", + "content-disposition": "^0.5.4", + "fastify-plugin": "^4.5.1", + "fastq": "^1.17.1", + "glob": "^10.3.10" }, "devDependencies": { "@fastify/compress": "^7.0.0", - "@fastify/pre-commit": "^2.0.2", - "@types/node": "^20.1.0", - "@typescript-eslint/eslint-plugin": "^7.1.0", - "@typescript-eslint/parser": "^7.1.0", + "@fastify/pre-commit": "^2.1.0", + "@types/node": "^20.11.30", + "@typescript-eslint/eslint-plugin": "^7.3.1", + "@typescript-eslint/parser": "^7.3.1", "concat-stream": "^2.0.0", - "coveralls": "^3.0.4", - "eslint-plugin-typescript": "^0.14.0", - "fastify": "^4.0.0-rc.2", - "handlebars": "^4.7.6", - "pino": "^8.4.2", - "proxyquire": "^2.1.0", - "simple-get": "^4.0.0", + "coveralls": "^3.1.1", + "fastify": "^4.26.2", + "handlebars": "^4.7.8", + "pino": "^8.19.0", + "proxyquire": "^2.1.3", + "simple-get": "^4.0.1", "snazzy": "^9.0.0", - "standard": "^17.0.0", - "tap": "^16.0.0", - "tsd": "^0.30.0", - "typescript": "^5.1.6" + "standard": "^17.1.0", + "tap": "^18.7.1", + "tsd": "^0.30.7", + "typescript": "^5.4.3" }, "tsd": { "directory": "test/types"