@fastify/static 7.0.2 → 7.0.3
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 +0 -0
- package/.gitattributes +0 -0
- package/.github/dependabot.yml +0 -0
- package/.github/stale.yml +0 -0
- package/.github/workflows/ci.yml +0 -0
- package/.taprc +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/example/public/.hidden/sample.json +0 -0
- package/example/public/images/sample.jpg +0 -0
- package/example/public/index.css +0 -0
- package/example/public/index.html +0 -0
- package/example/public/index.js +0 -0
- package/example/public2/test.css +0 -0
- package/example/public2/test.html +0 -0
- package/example/server-compress.js +0 -0
- package/example/server-dir-list.js +0 -0
- package/example/server-hidden-file.js +0 -0
- package/example/server.js +0 -0
- package/index.js +7 -2
- package/lib/dirList.js +0 -0
- package/package.json +2 -2
- package/test/content-type/binary +0 -0
- package/test/content-type/binary.br +0 -0
- package/test/content-type/index.css +0 -0
- package/test/content-type/index.css.br +0 -0
- package/test/content-type/index.html +0 -0
- package/test/content-type/index.html.br +0 -0
- package/test/content-type/sample.jpg +0 -0
- package/test/content-type/test.txt +0 -0
- package/test/content-type/test.txt.br +0 -0
- package/test/content-type.test.js +0 -0
- package/test/dir-list.test.js +0 -0
- package/test/static/.example +0 -0
- package/test/static/a .md +0 -0
- package/test/static/deep/path/for/test/index.html +0 -0
- package/test/static/deep/path/for/test/purpose/foo.html +0 -0
- package/test/static/foo.html +0 -0
- package/test/static/foobar.html +0 -0
- package/test/static/index.css +0 -0
- package/test/static/index.html +0 -0
- package/test/static/shallow/sample.jpg +0 -0
- package/test/static-dotfiles/.aaa +0 -0
- package/test/static-dotfiles/dir/index.html +0 -0
- package/test/static-dotfiles/test.txt +0 -0
- package/test/static-encode/[...]/a .md +0 -0
- package/test/static-hidden/.hidden/sample.json +0 -0
- package/test/static-pre-compressed/all-three.html +0 -0
- package/test/static-pre-compressed/all-three.html.br +0 -0
- package/test/static-pre-compressed/all-three.html.gz +0 -0
- package/test/static-pre-compressed/dir/index.html +0 -0
- package/test/static-pre-compressed/dir/index.html.br +0 -0
- package/test/static-pre-compressed/dir-gz/index.html +0 -0
- package/test/static-pre-compressed/dir-gz/index.html.gz +0 -0
- package/test/static-pre-compressed/empty/.gitkeep +0 -0
- package/test/static-pre-compressed/gzip-only.html +0 -0
- package/test/static-pre-compressed/gzip-only.html.gz +0 -0
- package/test/static-pre-compressed/index.html +0 -0
- package/test/static-pre-compressed/index.html.br +0 -0
- package/test/static-pre-compressed/sample.jpg +0 -0
- package/test/static-pre-compressed/sample.jpg.br +0 -0
- package/test/static-pre-compressed/uncompressed.html +0 -0
- package/test/static-symbolic-link/origin/subdir/subdir/index.html +0 -0
- package/test/static.test.js +39 -5
- package/test/static2/bar.html +0 -0
- package/test/static2/index.html +0 -0
- package/tsconfig.eslint.json +0 -0
- package/types/index.d.ts +0 -0
- package/types/index.test-d.ts +0 -0
package/.eslintrc.json
CHANGED
|
File without changes
|
package/.gitattributes
CHANGED
|
File without changes
|
package/.github/dependabot.yml
CHANGED
|
File without changes
|
package/.github/stale.yml
CHANGED
|
File without changes
|
package/.github/workflows/ci.yml
CHANGED
|
File without changes
|
package/.taprc
CHANGED
|
File without changes
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/example/public/index.css
CHANGED
|
File without changes
|
|
File without changes
|
package/example/public/index.js
CHANGED
|
File without changes
|
package/example/public2/test.css
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/example/server.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
@@ -111,8 +111,13 @@ async function fastifyStatic (fastify, opts) {
|
|
|
111
111
|
throw new Error('"wildcard" option must be a boolean')
|
|
112
112
|
}
|
|
113
113
|
if (opts.wildcard === undefined || opts.wildcard === true) {
|
|
114
|
-
fastify.
|
|
115
|
-
|
|
114
|
+
fastify.route({
|
|
115
|
+
...routeOpts,
|
|
116
|
+
method: ['HEAD', 'GET'],
|
|
117
|
+
path: prefix + '*',
|
|
118
|
+
handler (req, reply) {
|
|
119
|
+
pumpSendToReply(req, reply, '/' + req.params['*'], sendOptions.root)
|
|
120
|
+
}
|
|
116
121
|
})
|
|
117
122
|
if (opts.redirect === true && prefix !== opts.prefix) {
|
|
118
123
|
fastify.get(opts.prefix, routeOpts, (req, reply) => {
|
package/lib/dirList.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/static",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3",
|
|
4
4
|
"description": "Plugin for serving static files as fast as possible.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"snazzy": "^9.0.0",
|
|
56
56
|
"standard": "^17.0.0",
|
|
57
57
|
"tap": "^16.0.0",
|
|
58
|
-
"tsd": "^0.
|
|
58
|
+
"tsd": "^0.31.0",
|
|
59
59
|
"typescript": "^5.1.6"
|
|
60
60
|
},
|
|
61
61
|
"tsd": {
|
package/test/content-type/binary
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/dir-list.test.js
CHANGED
|
File without changes
|
package/test/static/.example
CHANGED
|
File without changes
|
package/test/static/a .md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/static/foo.html
CHANGED
|
File without changes
|
package/test/static/foobar.html
CHANGED
|
File without changes
|
package/test/static/index.css
CHANGED
|
File without changes
|
package/test/static/index.html
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/static.test.js
CHANGED
|
@@ -1740,7 +1740,7 @@ t.test('with fastify-compress', t => {
|
|
|
1740
1740
|
})
|
|
1741
1741
|
})
|
|
1742
1742
|
t.test('register /static/ with schemaHide true', t => {
|
|
1743
|
-
t.plan(
|
|
1743
|
+
t.plan(3)
|
|
1744
1744
|
|
|
1745
1745
|
const pluginOptions = {
|
|
1746
1746
|
root: path.join(__dirname, '/static'),
|
|
@@ -1780,7 +1780,7 @@ t.test('register /static/ with schemaHide true', t => {
|
|
|
1780
1780
|
})
|
|
1781
1781
|
|
|
1782
1782
|
t.test('register /static/ with schemaHide false', t => {
|
|
1783
|
-
t.plan(
|
|
1783
|
+
t.plan(3)
|
|
1784
1784
|
|
|
1785
1785
|
const pluginOptions = {
|
|
1786
1786
|
root: path.join(__dirname, '/static'),
|
|
@@ -1820,7 +1820,7 @@ t.test('register /static/ with schemaHide false', t => {
|
|
|
1820
1820
|
})
|
|
1821
1821
|
|
|
1822
1822
|
t.test('register /static/ without schemaHide', t => {
|
|
1823
|
-
t.plan(
|
|
1823
|
+
t.plan(3)
|
|
1824
1824
|
|
|
1825
1825
|
const pluginOptions = {
|
|
1826
1826
|
root: path.join(__dirname, '/static'),
|
|
@@ -2957,7 +2957,7 @@ t.test('inject support', async (t) => {
|
|
|
2957
2957
|
})
|
|
2958
2958
|
|
|
2959
2959
|
t.test('routes should use custom errorHandler premature stream close', t => {
|
|
2960
|
-
t.plan(
|
|
2960
|
+
t.plan(3)
|
|
2961
2961
|
|
|
2962
2962
|
const pluginOptions = {
|
|
2963
2963
|
root: path.join(__dirname, '/static'),
|
|
@@ -2992,7 +2992,7 @@ t.test('routes should use custom errorHandler premature stream close', t => {
|
|
|
2992
2992
|
})
|
|
2993
2993
|
|
|
2994
2994
|
t.test('routes should fallback to default errorHandler', t => {
|
|
2995
|
-
t.plan(
|
|
2995
|
+
t.plan(3)
|
|
2996
2996
|
|
|
2997
2997
|
const pluginOptions = {
|
|
2998
2998
|
root: path.join(__dirname, '/static'),
|
|
@@ -3962,3 +3962,37 @@ t.test(
|
|
|
3962
3962
|
t.same(response2.body, aContent)
|
|
3963
3963
|
}
|
|
3964
3964
|
)
|
|
3965
|
+
|
|
3966
|
+
t.test('content-length in head route should not return zero when using wildcard', t => {
|
|
3967
|
+
t.plan(6)
|
|
3968
|
+
|
|
3969
|
+
const pluginOptions = {
|
|
3970
|
+
root: path.join(__dirname, '/static')
|
|
3971
|
+
}
|
|
3972
|
+
const fastify = Fastify()
|
|
3973
|
+
|
|
3974
|
+
fastify.register(fastifyStatic, pluginOptions)
|
|
3975
|
+
|
|
3976
|
+
t.teardown(fastify.close.bind(fastify))
|
|
3977
|
+
|
|
3978
|
+
fastify.listen({ port: 0 }, err => {
|
|
3979
|
+
t.error(err)
|
|
3980
|
+
|
|
3981
|
+
fastify.server.unref()
|
|
3982
|
+
|
|
3983
|
+
const file = fs.readFileSync(path.join(__dirname, '/static/index.html'))
|
|
3984
|
+
const contentLength = Buffer.byteLength(file).toString()
|
|
3985
|
+
|
|
3986
|
+
simple.concat({
|
|
3987
|
+
method: 'HEAD',
|
|
3988
|
+
url: 'http://localhost:' + fastify.server.address().port + '/index.html',
|
|
3989
|
+
followRedirect: false
|
|
3990
|
+
}, (err, response, body) => {
|
|
3991
|
+
t.error(err)
|
|
3992
|
+
t.equal(response.statusCode, 200)
|
|
3993
|
+
t.equal(response.headers['content-type'], 'text/html; charset=UTF-8')
|
|
3994
|
+
t.equal(response.headers['content-length'], contentLength)
|
|
3995
|
+
t.equal(body.toString(), '')
|
|
3996
|
+
})
|
|
3997
|
+
})
|
|
3998
|
+
})
|
package/test/static2/bar.html
CHANGED
|
File without changes
|
package/test/static2/index.html
CHANGED
|
File without changes
|
package/tsconfig.eslint.json
CHANGED
|
File without changes
|
package/types/index.d.ts
CHANGED
|
File without changes
|
package/types/index.test-d.ts
CHANGED
|
File without changes
|