Skip to content

fix(fastify) New files requires a server restart to be served#523

Open
SnakeDrak wants to merge 1 commit into
nestjs:masterfrom
SnakeDrak:master
Open

fix(fastify) New files requires a server restart to be served#523
SnakeDrak wants to merge 1 commit into
nestjs:masterfrom
SnakeDrak:master

Conversation

@SnakeDrak

@SnakeDrak SnakeDrak commented May 19, 2021

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[X] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

New files are not served using fastify. On this issue or in the documentation of fastify-static is commented that using the wildcard option to false will create only routes to the current files in the system and it will not serve new files.

The issue was introduced on this PR due to the fail of the redirection to the index.

Steps to reproduce it

  • Start with nest/sample/24-servestatic/.
  • Add the FastifyAdapter and start the server.
  • Create a new file, for example test.txt under the static folder client.
  • Try to navigate to /test.txt.

It will redirect to the index.html and the test file will not be served.

What is the new behavior?

The solution is to remove the wildcard option to false by default. However, it would create 404 error when the file doesn't exist and it would not redirect to the index. To solve this latest situation, I have caught the 404 error when they are generated under the renderPath with the fastify adapter to serve the index file, supporting the current behaviour.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

7rulnik added a commit to 7rulnik/serve-static that referenced this pull request Sep 9, 2021
@7rulnik

7rulnik commented Sep 17, 2021

Copy link
Copy Markdown

@tristan957 could you take a look at this? We had successfully battle-tested it. For now, it's huge blocker for development with webpack for example.

@tristan957

Copy link
Copy Markdown

I am not a maintainer, nor am I at all familiar with fastify. Maybe you're meaning to tag someone else

@7rulnik

7rulnik commented Sep 17, 2021

Copy link
Copy Markdown

Ooops yeah, my bad

Meant to tag @kamilmysliwiec

@rudfoss

rudfoss commented Sep 13, 2022

Copy link
Copy Markdown

Hi, I've stumbled across the same problem. Any chance of this getting merged? Or at least giving us control over the wildcard parameter?

@jongomes

jongomes commented Dec 2, 2022

Copy link
Copy Markdown

+1

"@nestjs/platform-fastify": "^9.2.1",
"@fastify/static": "^6.5.1",
"@nestjs/schedule": "^2.1.0",
"@nestjs/serve-static": "^3.0.0",

@ffind

ffind commented Mar 3, 2023

Copy link
Copy Markdown

Hi, I got the issue with new files are not being served. But there are no way to access wildcard in fastify. So how to serve new files then?

      "@fastify/static": "^6.9.0",
      "@nestjs/serve-static": "^3.0.1",

@wenpeng-song

Copy link
Copy Markdown

Hi, I've stumbled across the same problem. Any chance of this getting merged? Or at least giving us control over the wildcard parameter?

+1

@ctkc

ctkc commented May 28, 2024

Copy link
Copy Markdown

Is there a chance we can merge this? I really need it. Thank you @SnakeDrak for the work! cc @kamilmysliwiec

@thekhegay

Copy link
Copy Markdown

@kamilmysliwiec

@debugelton

Copy link
Copy Markdown

@kamilmysliwiec I feel the same way, so serve-static is useless for me. What a pity. Thanks @SnakeDrak for the fix

@mibeScheer

Copy link
Copy Markdown

Why is no one merging this fix?

@volkflo

volkflo commented Jul 4, 2025

Copy link
Copy Markdown

Ohh I created #1727 yesterday, without noticing that this is fixed already...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.