未验证 提交 633dd87b 编写于 作者: T Tim Neutkens 提交者: GitHub

Handle 404 thrown from send (#5779)

上级 4322bb13
......@@ -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
......
......@@ -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']
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册