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

Handle page 404 properly in production. (#3648)

This is needed for multi-zones feature
This commit is contained in:
Arunoda Susiripala 2018-02-01 13:56:08 +05:30 committed by Tim Neutkens
parent 80fc0f4511
commit 944668c6c4

View file

@ -3,6 +3,7 @@ import { resolve, join, sep } from 'path'
import { parse as parseUrl } from 'url'
import { parse as parseQs } from 'querystring'
import fs from 'fs'
import fsAsync from 'mz/fs'
import http, { STATUS_CODES } from 'http'
import {
renderToHTML,
@ -216,6 +217,13 @@ export default class Server {
}
const p = join(this.dir, this.dist, 'bundles', 'pages', `${page}.js`)
// [production] If the page is not exists, we need to send a proper Next.js style 404
// Otherwise, it'll affect the multi-zones feature.
if (!(await fsAsync.exists(p))) {
return await renderScriptError(req, res, page, { code: 'ENOENT' }, {}, this.renderOpts)
}
await this.serveStatic(req, res, p)
},