Skip to content

redirect doesn't work when preCompressed is true #470

@blue-wing

Description

@blue-wing

Prerequisites

  • I have written a descriptive issue title
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions