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

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

Open SnakeDrak opened this issue 3 years ago • 8 comments

PR Checklist

Please check if your PR fulfills the following requirements:

  • [X] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [ ] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been added / updated (for bug fixes / features)

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

SnakeDrak avatar May 19 '21 09:05 SnakeDrak

@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.

7rulnik avatar Sep 17 '21 02:09 7rulnik

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

tristan957 avatar Sep 17 '21 02:09 tristan957

Ooops yeah, my bad

Meant to tag @kamilmysliwiec

7rulnik avatar Sep 17 '21 08:09 7rulnik

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

rudfoss avatar Sep 13 '22 06:09 rudfoss

+1

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

jongomes avatar Dec 02 '22 17:12 jongomes

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",

ffind avatar Mar 03 '23 18:03 ffind

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

wenpeng-song avatar Dec 06 '23 08:12 wenpeng-song