@fastify/static 6.8.0 → 6.9.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/index.js +1 -1
- package/package.json +1 -1
- package/test/static.test.js +57 -0
package/index.js
CHANGED
package/package.json
CHANGED
package/test/static.test.js
CHANGED
|
@@ -3646,3 +3646,60 @@ t.test('should serve files into hidden dir without wildcard option', (t) => {
|
|
|
3646
3646
|
})
|
|
3647
3647
|
})
|
|
3648
3648
|
})
|
|
3649
|
+
|
|
3650
|
+
t.test(
|
|
3651
|
+
'will serve pre-compressed files with .gzip if multi-root',
|
|
3652
|
+
async (t) => {
|
|
3653
|
+
const pluginOptions = {
|
|
3654
|
+
root: [path.join(__dirname, '/static-pre-compressed'), path.join(__dirname, '/static')],
|
|
3655
|
+
preCompressed: true
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
const fastify = Fastify()
|
|
3659
|
+
|
|
3660
|
+
fastify.register(fastifyStatic, pluginOptions)
|
|
3661
|
+
t.teardown(fastify.close.bind(fastify))
|
|
3662
|
+
|
|
3663
|
+
const response = await fastify.inject({
|
|
3664
|
+
method: 'GET',
|
|
3665
|
+
url: 'all-three.html',
|
|
3666
|
+
headers: {
|
|
3667
|
+
'accept-encoding': '*, *'
|
|
3668
|
+
}
|
|
3669
|
+
})
|
|
3670
|
+
|
|
3671
|
+
genericResponseChecks(t, response)
|
|
3672
|
+
t.equal(response.headers['content-encoding'], 'gzip')
|
|
3673
|
+
t.equal(response.statusCode, 200)
|
|
3674
|
+
t.same(response.rawPayload, allThreeGzip)
|
|
3675
|
+
t.end()
|
|
3676
|
+
}
|
|
3677
|
+
)
|
|
3678
|
+
|
|
3679
|
+
t.test(
|
|
3680
|
+
'will still serve un-compressed files with multi-root and preCompressed as true',
|
|
3681
|
+
async (t) => {
|
|
3682
|
+
const pluginOptions = {
|
|
3683
|
+
root: [path.join(__dirname, '/static-pre-compressed'), path.join(__dirname, '/static')],
|
|
3684
|
+
preCompressed: true
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
const fastify = Fastify()
|
|
3688
|
+
|
|
3689
|
+
fastify.register(fastifyStatic, pluginOptions)
|
|
3690
|
+
t.teardown(fastify.close.bind(fastify))
|
|
3691
|
+
|
|
3692
|
+
const response = await fastify.inject({
|
|
3693
|
+
method: 'GET',
|
|
3694
|
+
url: 'foobar.html',
|
|
3695
|
+
headers: {
|
|
3696
|
+
'accept-encoding': '*, *'
|
|
3697
|
+
}
|
|
3698
|
+
})
|
|
3699
|
+
|
|
3700
|
+
genericResponseChecks(t, response)
|
|
3701
|
+
t.equal(response.statusCode, 200)
|
|
3702
|
+
t.same(response.body, foobarContent)
|
|
3703
|
+
t.end()
|
|
3704
|
+
}
|
|
3705
|
+
)
|