@fastify/static 6.11.1 → 6.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +28 -48
- package/index.js +13 -11
- package/lib/dirList.js +4 -4
- package/package.json +2 -1
- package/test/static.test.js +3 -3
- package/tsconfig.eslint.json +9 -12
package/.eslintrc.json
CHANGED
|
@@ -1,51 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"env": { "node": true },
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaVersion": 6,
|
|
13
|
-
"sourceType": "module",
|
|
14
|
-
"project": "./tsconfig.eslint.json",
|
|
15
|
-
"createDefaultProgram": true
|
|
16
|
-
},
|
|
17
|
-
"rules": {
|
|
18
|
-
"no-console": "off",
|
|
19
|
-
"@typescript-eslint/indent": ["error", 2],
|
|
20
|
-
"semi": ["error", "never"],
|
|
21
|
-
"import/export": "off" // this errors on multiple exports (overload interfaces)
|
|
22
|
-
},
|
|
23
|
-
"overrides": [
|
|
24
|
-
{
|
|
25
|
-
"files": ["*.d.ts","*.test-d.ts"],
|
|
26
|
-
"rules": {
|
|
27
|
-
"no-use-before-define": "off",
|
|
28
|
-
"no-redeclare": "off",
|
|
29
|
-
"@typescript-eslint/no-explicit-any": "off"
|
|
30
|
-
}
|
|
2
|
+
"plugins": ["@typescript-eslint"],
|
|
3
|
+
"extends": ["eslint:recommended", "standard"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["types/*.test-d.ts", "types/*.d.ts"],
|
|
7
|
+
"parser": "@typescript-eslint/parser",
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"project": ["./tsconfig.eslint.json"]
|
|
31
10
|
},
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
}
|
|
11
|
+
"extends": [
|
|
12
|
+
"plugin:@typescript-eslint/recommended",
|
|
13
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
14
|
+
],
|
|
15
|
+
"rules": {
|
|
16
|
+
"no-use-before-define": "off",
|
|
17
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
18
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
19
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
20
|
+
"@typescript-eslint/no-floating-promises": "off",
|
|
21
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
22
|
+
"@typescript-eslint/no-unsafe-argument": "off",
|
|
23
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
24
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
25
|
+
"@typescript-eslint/no-misused-promises": ["error", {
|
|
26
|
+
"checksVoidReturn": false
|
|
27
|
+
}]
|
|
49
28
|
}
|
|
50
|
-
|
|
51
|
-
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
package/index.js
CHANGED
|
@@ -14,12 +14,12 @@ const contentDisposition = require('content-disposition')
|
|
|
14
14
|
|
|
15
15
|
const dirList = require('./lib/dirList')
|
|
16
16
|
|
|
17
|
-
const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, '
|
|
18
|
-
const backslashRegex = /\\/
|
|
19
|
-
const startForwardSlashRegex = /^\//
|
|
20
|
-
const endForwardSlashRegex = /\/$/
|
|
21
|
-
const doubleForwardSlashRegex = /\/\//
|
|
22
|
-
const asteriskRegex = /\*/
|
|
17
|
+
const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, 'gu')
|
|
18
|
+
const backslashRegex = /\\/gu
|
|
19
|
+
const startForwardSlashRegex = /^\//u
|
|
20
|
+
const endForwardSlashRegex = /\/$/u
|
|
21
|
+
const doubleForwardSlashRegex = /\/\//gu
|
|
22
|
+
const asteriskRegex = /\*/gu
|
|
23
23
|
|
|
24
24
|
const supportedEncodings = ['br', 'gzip', 'deflate']
|
|
25
25
|
send.mime.default_type = 'application/octet-stream'
|
|
@@ -396,7 +396,9 @@ async function fastifyStatic (fastify, opts) {
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
function serveFileHandler (req, reply) {
|
|
399
|
-
|
|
399
|
+
// TODO: remove the fallback branch when bump major
|
|
400
|
+
/* istanbul ignore next */
|
|
401
|
+
const routeConfig = req.routeOptions?.config || req.routeConfig
|
|
400
402
|
pumpSendToReply(req, reply, routeConfig.file, routeConfig.rootPath)
|
|
401
403
|
}
|
|
402
404
|
}
|
|
@@ -434,7 +436,7 @@ function checkRootPathForErrors (fastify, rootPath) {
|
|
|
434
436
|
throw new Error('"root" option array requires one or more paths')
|
|
435
437
|
}
|
|
436
438
|
|
|
437
|
-
if (
|
|
439
|
+
if (new Set(rootPath).size !== rootPath.length) {
|
|
438
440
|
throw new Error(
|
|
439
441
|
'"root" option array contains one or more duplicate paths'
|
|
440
442
|
)
|
|
@@ -496,7 +498,7 @@ function findIndexFile (pathname, root, indexFiles = ['index.html']) {
|
|
|
496
498
|
try {
|
|
497
499
|
const stats = statSync(p)
|
|
498
500
|
return !stats.isDirectory()
|
|
499
|
-
} catch
|
|
501
|
+
} catch {
|
|
500
502
|
return false
|
|
501
503
|
}
|
|
502
504
|
})
|
|
@@ -540,7 +542,7 @@ function getRedirectUrl (url) {
|
|
|
540
542
|
const parsed = new URL(url, 'http://localhost.com/')
|
|
541
543
|
const parsedPathname = parsed.pathname
|
|
542
544
|
return parsedPathname + (parsedPathname[parsedPathname.length - 1] !== '/' ? '/' : '') + (parsed.search || '')
|
|
543
|
-
} catch
|
|
545
|
+
} catch {
|
|
544
546
|
// the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack
|
|
545
547
|
/* istanbul ignore next */
|
|
546
548
|
const err = new Error(`Invalid redirect URL: ${url}`)
|
|
@@ -552,7 +554,7 @@ function getRedirectUrl (url) {
|
|
|
552
554
|
}
|
|
553
555
|
|
|
554
556
|
module.exports = fp(fastifyStatic, {
|
|
555
|
-
fastify: '
|
|
557
|
+
fastify: '4.x',
|
|
556
558
|
name: '@fastify/static'
|
|
557
559
|
})
|
|
558
560
|
module.exports.default = fastifyStatic
|
package/lib/dirList.js
CHANGED
|
@@ -27,7 +27,7 @@ const dirList = {
|
|
|
27
27
|
let stats
|
|
28
28
|
try {
|
|
29
29
|
stats = await fs.stat(path.join(dir, filename))
|
|
30
|
-
} catch
|
|
30
|
+
} catch {
|
|
31
31
|
return
|
|
32
32
|
}
|
|
33
33
|
const entry = { name: filename, stats }
|
|
@@ -58,7 +58,7 @@ const dirList = {
|
|
|
58
58
|
let stats
|
|
59
59
|
try {
|
|
60
60
|
stats = await fs.stat(filePath)
|
|
61
|
-
} catch
|
|
61
|
+
} catch {
|
|
62
62
|
return
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -112,7 +112,7 @@ const dirList = {
|
|
|
112
112
|
let entries
|
|
113
113
|
try {
|
|
114
114
|
entries = await dirList.list(dir, options, dotfiles)
|
|
115
|
-
} catch
|
|
115
|
+
} catch {
|
|
116
116
|
return reply.callNotFound()
|
|
117
117
|
}
|
|
118
118
|
const format = reply.request.query.format || options.format
|
|
@@ -146,7 +146,7 @@ const dirList = {
|
|
|
146
146
|
route = path.normalize(path.join(route, '..'))
|
|
147
147
|
}
|
|
148
148
|
return {
|
|
149
|
-
href: path.join(prefix, route, entry.name).replace(/\\/
|
|
149
|
+
href: path.join(prefix, route, entry.name).replace(/\\/gu, '/'),
|
|
150
150
|
name: entry.name,
|
|
151
151
|
stats: entry.stats,
|
|
152
152
|
extendedInfo: entry.extendedInfo
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/static",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.0",
|
|
4
4
|
"description": "Plugin for serving static files as fast as possible.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
6
7
|
"types": "types/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"coverage": "npm run test:unit -- --coverage-report=html",
|
package/test/static.test.js
CHANGED
|
@@ -1000,7 +1000,7 @@ t.test('sendFile disabled', (t) => {
|
|
|
1000
1000
|
fastify.register(fastifyStatic, pluginOptions)
|
|
1001
1001
|
|
|
1002
1002
|
fastify.get('/foo/bar', function (req, reply) {
|
|
1003
|
-
if (
|
|
1003
|
+
if (reply.sendFile === undefined) {
|
|
1004
1004
|
reply.send('pass')
|
|
1005
1005
|
} else {
|
|
1006
1006
|
reply.send('fail')
|
|
@@ -1277,7 +1277,7 @@ t.test('sendFile disabled', (t) => {
|
|
|
1277
1277
|
fastify.register(fastifyStatic, pluginOptions)
|
|
1278
1278
|
|
|
1279
1279
|
fastify.get('/foo/bar', function (req, reply) {
|
|
1280
|
-
if (
|
|
1280
|
+
if (reply.sendFile === undefined) {
|
|
1281
1281
|
reply.send('pass')
|
|
1282
1282
|
} else {
|
|
1283
1283
|
reply.send('fail')
|
|
@@ -1316,7 +1316,7 @@ t.test('download disabled', (t) => {
|
|
|
1316
1316
|
fastify.register(fastifyStatic, pluginOptions)
|
|
1317
1317
|
|
|
1318
1318
|
fastify.get('/foo/bar', function (req, reply) {
|
|
1319
|
-
if (
|
|
1319
|
+
if (reply.download === undefined) {
|
|
1320
1320
|
t.equal(reply.download, undefined)
|
|
1321
1321
|
reply.send('pass')
|
|
1322
1322
|
} else {
|
package/tsconfig.eslint.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"types/*.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"lib": ["ES2018"],
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"noEmit": true,
|
|
7
|
+
"strict": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["types/*.test-d.ts", "types/*.d.ts"]
|
|
10
|
+
}
|