Skip to content

Commit

Permalink
feat: preparation for fastify@5 (#444)
Browse files Browse the repository at this point in the history
* Update for v5

* c8 ignore

* remove dep

* c8

---------

Co-authored-by: Gürgün Dayıoğlu <[email protected]>
  • Loading branch information
bilalshareef and gurgunday authored Mar 26, 2024
1 parent 4e39bd8 commit 60504fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 6 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning

Code scanning / CodeQL

Information exposure through a stack trace Medium

This information exposed to the user depends on
stack trace information
.
}
} /* 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)) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -495,7 +492,7 @@ function findIndexFile (pathname, root, indexFiles = ['index.html']) {
}
})
}
/* istanbul ignore next */
/* c8 ignore next */
return false
}

Expand Down Expand Up @@ -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, {
Expand Down
41 changes: 20 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 60504fa

Please sign in to comment.