1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Handle 404 thrown from send (#5779)

This commit is contained in:
Tim Neutkens 2018-11-30 17:09:23 +01:00 committed by GitHub
parent 4322bb13dd
commit 633dd87b18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -231,7 +231,7 @@ export default class Server {
try {
return await serveStatic(req, res, path)
} catch (err) {
if (err.code === 'ENOENT') {
if (err.code === 'ENOENT' || err.statusCode === 404) {
this.render404(req, res)
} else {
throw err

View file

@ -61,6 +61,12 @@ describe('Production Usage', () => {
expect(res.status).toBe(404)
})
it('should render 404 for dotfiles in /static', async () => {
const url = `http://localhost:${appPort}/static/.env`
const res = await fetch(url)
expect(res.status).toBe(404)
})
it('should render 501 if the HTTP method is not GET or HEAD', async () => {
const url = `http://localhost:${appPort}/_next/abcdef`
const methods = ['POST', 'PUT', 'DELETE']