Unverified Commit 633dd87b authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Handle 404 thrown from send (#5779)

parent 4322bb13
...@@ -231,7 +231,7 @@ export default class Server { ...@@ -231,7 +231,7 @@ export default class Server {
try { try {
return await serveStatic(req, res, path) return await serveStatic(req, res, path)
} catch (err) { } catch (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT' || err.statusCode === 404) {
this.render404(req, res) this.render404(req, res)
} else { } else {
throw err throw err
......
...@@ -61,6 +61,12 @@ describe('Production Usage', () => { ...@@ -61,6 +61,12 @@ describe('Production Usage', () => {
expect(res.status).toBe(404) 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 () => { it('should render 501 if the HTTP method is not GET or HEAD', async () => {
const url = `http://localhost:${appPort}/_next/abcdef` const url = `http://localhost:${appPort}/_next/abcdef`
const methods = ['POST', 'PUT', 'DELETE'] const methods = ['POST', 'PUT', 'DELETE']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment