Skip to content

Serving new files when using the fastify platform does not work #1727

@volkflo

Description

@volkflo

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

We experienced a strange behavior between fastify and express.
In express it is possible that newly added files are served.
With fastify however this is not possible.

This is due to the fastify configuration in the nestjs/static adapter.

As the flag wildcard is always set to false, new files are not loaded from the disc anymore.
You can read more about that in the fastify documentation: https://github.com/fastify/fastify-static#wildcard

Default: true
If true, @fastify/static adds a wildcard route to serve files. If false, it globs the filesystem for all defined files in the served folder (${root}//) and creates the necessary routes, but will not serve newly added files.

It would be nice to make this configurable by a setting.

Minimum reproduction code

https://github.com/volkflo/fastify-reproducer

Steps to reproduce

  1. npm i
  2. npm run start
  3. Run curl http://localhost:3000/ui/index.hmtl -> works
  4. Run echo "hello fastify" > client/abc.txt
  5. Run curl http://localhost:3000/ui/abc.txt -> 404 error

Expected behavior

Package version

5.0.3

NestJS version

11.1.3

Node.js version

20

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Please let us know if you need more information or have any further questions
Co-Tested with https://github.com/mibeScheer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions