fastify-static icon indicating copy to clipboard operation
fastify-static copied to clipboard

`redirect` doesn't work when `preCompressed` is true

Open blue-wing opened this issue 1 year ago • 1 comments

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.

blue-wing avatar Sep 07 '24 07:09 blue-wing

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

mcollina avatar Sep 11 '24 15:09 mcollina

@mcollina I have fixed and sent a PR :)

genki avatar Feb 15 '25 00:02 genki