@fastify/static 8.0.0 → 8.0.2
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/index.js +5 -1
- package/package.json +2 -2
- package/test/static.test.js +38 -0
package/index.js
CHANGED
|
@@ -350,7 +350,11 @@ async function fastifyStatic (fastify, opts) {
|
|
|
350
350
|
break
|
|
351
351
|
}
|
|
352
352
|
case 'file': {
|
|
353
|
-
reply.
|
|
353
|
+
// reply.raw.statusCode by default 200
|
|
354
|
+
// when ever the user changed it, we respect the status code
|
|
355
|
+
// otherwise use send provided status code
|
|
356
|
+
const newStatusCode = reply.statusCode !== 200 ? reply.statusCode : statusCode
|
|
357
|
+
reply.code(newStatusCode)
|
|
354
358
|
if (setHeaders !== undefined) {
|
|
355
359
|
setHeaders(reply.raw, metadata.path, metadata.stat)
|
|
356
360
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/static",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Plugin for serving static files as fast as possible.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/node": "^22.0.0",
|
|
43
43
|
"concat-stream": "^2.0.0",
|
|
44
44
|
"eslint": "^9.9.0",
|
|
45
|
-
"fastify": "^5.0.0
|
|
45
|
+
"fastify": "^5.0.0",
|
|
46
46
|
"neostandard": "^0.11.3",
|
|
47
47
|
"pino": "^9.1.0",
|
|
48
48
|
"proxyquire": "^2.1.3",
|
package/test/static.test.js
CHANGED
|
@@ -4023,3 +4023,41 @@ t.test('content-length in head route should not return zero when using wildcard'
|
|
|
4023
4023
|
})
|
|
4024
4024
|
})
|
|
4025
4025
|
})
|
|
4026
|
+
|
|
4027
|
+
t.test('respect the .code when using with sendFile', t => {
|
|
4028
|
+
t.plan(6)
|
|
4029
|
+
|
|
4030
|
+
const pluginOptions = {
|
|
4031
|
+
root: path.join(__dirname, '/static')
|
|
4032
|
+
}
|
|
4033
|
+
const fastify = Fastify()
|
|
4034
|
+
|
|
4035
|
+
fastify.register(fastifyStatic, pluginOptions)
|
|
4036
|
+
|
|
4037
|
+
fastify.get('/custom', (_, reply) => {
|
|
4038
|
+
return reply.code(404).type('text/html').sendFile('foo.html')
|
|
4039
|
+
})
|
|
4040
|
+
|
|
4041
|
+
t.teardown(fastify.close.bind(fastify))
|
|
4042
|
+
|
|
4043
|
+
fastify.listen({ port: 0 }, err => {
|
|
4044
|
+
t.error(err)
|
|
4045
|
+
|
|
4046
|
+
fastify.server.unref()
|
|
4047
|
+
|
|
4048
|
+
const file = fs.readFileSync(path.join(__dirname, '/static/foo.html'))
|
|
4049
|
+
const contentLength = Buffer.byteLength(file).toString()
|
|
4050
|
+
|
|
4051
|
+
simple.concat({
|
|
4052
|
+
method: 'HEAD',
|
|
4053
|
+
url: 'http://localhost:' + fastify.server.address().port + '/custom',
|
|
4054
|
+
followRedirect: false
|
|
4055
|
+
}, (err, response, body) => {
|
|
4056
|
+
t.error(err)
|
|
4057
|
+
t.equal(response.statusCode, 404)
|
|
4058
|
+
t.equal(response.headers['content-type'], 'text/html; charset=UTF-8')
|
|
4059
|
+
t.equal(response.headers['content-length'], contentLength)
|
|
4060
|
+
t.equal(body.toString(), '')
|
|
4061
|
+
})
|
|
4062
|
+
})
|
|
4063
|
+
})
|