serve-static
serve-static copied to clipboard
fix(fastify) New files requires a server restart to be served
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 folderclient
. - 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
@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.
I am not a maintainer, nor am I at all familiar with fastify. Maybe you're meaning to tag someone else
Ooops yeah, my bad
Meant to tag @kamilmysliwiec
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
"@nestjs/platform-fastify": "^9.2.1",
"@fastify/static": "^6.5.1",
"@nestjs/schedule": "^2.1.0",
"@nestjs/serve-static": "^3.0.0",
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",
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