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:
parent
80fc0f4511
commit
944668c6c4
|
@ -3,6 +3,7 @@ import { resolve, join, sep } from 'path'
|
||||||
import { parse as parseUrl } from 'url'
|
import { parse as parseUrl } from 'url'
|
||||||
import { parse as parseQs } from 'querystring'
|
import { parse as parseQs } from 'querystring'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import fsAsync from 'mz/fs'
|
||||||
import http, { STATUS_CODES } from 'http'
|
import http, { STATUS_CODES } from 'http'
|
||||||
import {
|
import {
|
||||||
renderToHTML,
|
renderToHTML,
|
||||||
|
@ -216,6 +217,13 @@ export default class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = join(this.dir, this.dist, 'bundles', 'pages', `${page}.js`)
|
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)
|
await this.serveStatic(req, res, p)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue