Skip to content

dir-list already sent with trailing slash #497

@jessekrubin

Description

@jessekrubin

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.x.x

Plugin version

8.x.x

Node.js version

20

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

rhel8 and ms windows

Description

When using the default json list for directories and fastify static trailing slashes trigger a reply-already sent error internally.

repro: https://github.com/jessekrubin/fastify-static-reply-sent

// fastify

import path from "node:path";
import Fastify from "fastify";

import FastifyStatic from "@fastify/static";
const fastify = Fastify({ logger: { level: "trace" } });

const pwd = process.cwd();
const root = path.join(pwd, "/node_modules");
console.log(root);
fastify
  .register(FastifyStatic, {
    root,
    redirect: false, // redirect true makes problem always happen
    prefix: "/node_modules",
    index: false,
    list: true,
  })
  .listen({ port: 3000 }, (err) => {
    if (err) throw err;
  });

// dir routes give me a 'already sent' error msg!

// NO PROBLEMO:
//   http://localhost:3000/node_modules/@fastify   <-- no trailing slash
// HAS PROBLEM:
//   http://localhost:3000/node_modules/           <-- trailing slash
//   http://localhost:3000/node_modules/@fastify/  <-- trailing slash

Link to code that reproduces the bug

https://github.com/jessekrubin/fastify-static-reply-sent

Expected Behavior

not throw an error or document how I am supposed to configure this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions