Skip to content

Commit

Permalink
Remove redundant parameter (#395)
Browse files Browse the repository at this point in the history
* remove unnecessary argument

* move supportedEncodings to near where it's used

* revert name change of fileHandler

* move handler out again
  • Loading branch information
gurgunday committed Jul 31, 2023
1 parent e29e22e commit ebfc5b0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ async function fastifyStatic (fastify, opts) {
}
routes.add(route)

setUpHeadAndGet(fastify, routeOpts, route, '/' + file, rootPath)
setUpHeadAndGet(routeOpts, route, '/' + file, rootPath)

const key = path.posix.basename(route)
if (indexes.includes(key) && !indexDirs.has(key)) {
Expand All @@ -370,16 +370,16 @@ async function fastifyStatic (fastify, opts) {
for (const [dirname, rootPath] of indexDirs.entries()) {
const pathname = dirname + (dirname.endsWith('/') ? '' : '/')
const file = '/' + pathname.replace(prefix, '')
setUpHeadAndGet(fastify, routeOpts, pathname, file, rootPath)
setUpHeadAndGet(routeOpts, pathname, file, rootPath)

if (opts.redirect === true) {
setUpHeadAndGet(fastify, routeOpts, pathname.replace(/\/$/, ''), file.replace(/\/$/, ''), rootPath)
setUpHeadAndGet(routeOpts, pathname.replace(/\/$/, ''), file.replace(/\/$/, ''), rootPath)
}
}
}
}

function setUpHeadAndGet (fastify, routeOpts, route, file, rootPath) {
function setUpHeadAndGet (routeOpts, route, file, rootPath) {
const toSetUp = {
...routeOpts,
method: ['HEAD', 'GET'],
Expand All @@ -398,6 +398,7 @@ async function fastifyStatic (fastify, opts) {
pumpSendToReply(req, reply, file, rootPath)
}
}

function normalizeRoot (root) {
if (root === undefined) {
return root
Expand Down Expand Up @@ -475,8 +476,6 @@ function checkPath (fastify, rootPath) {
}
}

const supportedEncodings = ['br', 'gzip', 'deflate']

function getContentType (path) {
const type = send.mime.getType(path) || send.mime.default_type

Expand Down Expand Up @@ -504,6 +503,8 @@ function findIndexFile (pathname, root, indexFiles = ['index.html']) {
return false
}

const supportedEncodings = ['br', 'gzip', 'deflate']

// Adapted from https://github.com/fastify/fastify-compress/blob/665e132fa63d3bf05ad37df3c20346660b71a857/index.js#L451
function getEncodingHeader (headers, checked) {
if (!('accept-encoding' in headers)) return
Expand Down

0 comments on commit ebfc5b0

Please sign in to comment.