fastify-static
fastify-static copied to clipboard
`redirect` doesn't work when `preCompressed` is true
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.28.1
Plugin version
7.0.4
Node.js version
22.8.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10
Description
Files:
dir/index.html
dir/index.html.br
main.js
main.js:
import fastifyStatic from "@fastify/static";
import Fastify from "fastify";
const fastify = Fastify({logger: true});
fastify.register(fastifyStatic, {
root: process.cwd(),
preCompressed: true,
redirect: true,
});
fastify.listen({port: 80});
When I navigate to http://localhost/dir, I don't get redirected to http://localhost/dir/ as expected.
The redirection only fails if either dir/index.html or dir/index.html.br exists. If dir is empty, the redirection succeeds and I get a 301 followed by a 404.
Link to code that reproduces the bug
No response
Expected Behavior
The redirection works fine if I comment out the line preCompressed: true.
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
@mcollina I have fixed and sent a PR :)