Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServeStaticModule serves non-existing paths #224

Closed
stovberpv opened this issue May 30, 2020 · 2 comments
Closed

ServeStaticModule serves non-existing paths #224

stovberpv opened this issue May 30, 2020 · 2 comments

Comments

@stovberpv
Copy link

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

  1. nest new testcase
  2. npm install --save @nestjs/serve-static
  3. Import ServeStaticModule.forRoot({ rootPath: join(process.cwd(), 'client') }) in app.module.ts
  4. Create folder testcase/client
  5. Create index file index.html under the testcase/client
  6. npm run start
  7. Make request at curl --location --request GET 'localhost:3000/foo'
  8. Got response HTTP/1.1 200 OK but expected HTTP/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:
@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/nest Jun 1, 2020
@kamilmysliwiec
Copy link
Member

We're tracking this here nestjs/docs.nestjs.com#1153

@MaximSagan
Copy link

@kamilmysliwiec Since you referenced that issue here, there's been no activity on that issue other than it getting closed 5 months later.

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

No branches or pull requests

3 participants