Closed
Description
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When using the @nestjs/serve-static
module, the server serves any path and does not return a 404 error even if the requested resource does not exist.
Project folder structure
.
├── client
│ └── index.hml
├── src
│ ├── app.module.ts
Input Code
// src\app.module.ts
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
imports: [
ServeStaticModule.forRoot({ rootPath: join(process.cwd(), 'client') })
],
Testing
Request an existing resource
GET / HTTP/1.1
Host: localhost:3000
Response
HTTP/1.1 200 OK
Request a nonexistent resource
GET /foo HTTP/1.1
Host: localhost:3000
Response
HTTP/1.1 200 OK
Expected behavior
Request a nonexistent resource
GET /foo HTTP/1.1
Host: localhost:3000
Response
HTTP/1.1 404 Not Found
Minimal reproduction of the problem with instructions
nest new testcase
npm install --save @nestjs/serve-static
- Import
ServeStaticModule.forRoot({ rootPath: join(process.cwd(), 'client') })
inapp.module.ts
- Create folder
testcase/client
- Create index file
index.html
under thetestcase/client
npm run start
- Make request at
curl --location --request GET 'localhost:3000/foo'
- Got response
HTTP/1.1 200 OK
but expectedHTTP/1.1 404 Not Found
What is the motivation / use case for changing the behavior?
In general, "serve-static" should follow the usual logic while serving files. If requested resource does not exists, an error is returned. Or in documentation should have a place where described this behavior and provided some instruction for handling that situations.
Environment
Nest version: 7.2.0
For Tooling issues:
- Node version: v12.16.3
- Platform: Windows
Others:
Metadata
Metadata
Assignees
Labels
No labels