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

Move ensurePage to DevServer (#5582)

It's no longer needed inside the `render()` function since we have a separate devServer
上级 1496ad62
......@@ -24,8 +24,6 @@ function getDynamicImportBundles (manifest, moduleIds) {
}, [])
}
const logger = console
// since send doesn't support wasm yet
send.mime.define({ 'application/wasm': ['wasm'] })
......@@ -63,7 +61,6 @@ async function doRender (req, res, pathname, query, {
err,
page,
buildId,
hotReloader,
assetPrefix,
runtimeConfig,
distDir,
......@@ -74,11 +71,6 @@ async function doRender (req, res, pathname, query, {
} = {}) {
page = page || pathname
// In dev mode we use on demand entries to compile the page before rendering
if (hotReloader) {
await hotReloader.ensurePage(page)
}
const documentPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_document')
const appPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_app')
let [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([
......@@ -203,7 +195,7 @@ export async function renderScriptError (req, res, page, error) {
return
}
logger.error(error.stack)
console.error(error.stack)
res.statusCode = 500
res.end('500 - Internal Error')
}
......
......@@ -8,7 +8,6 @@ export default class DevServer extends Server {
constructor (options) {
super(options)
this.hotReloader = new HotReloader(this.dir, { config: this.nextConfig, buildId: this.buildId })
this.renderOpts.hotReloader = this.hotReloader
this.renderOpts.dev = true
}
......@@ -90,6 +89,17 @@ export default class DevServer extends Server {
return this.renderErrorToHTML(compilationErr, req, res, pathname, query)
}
// In dev mode we use on demand entries to compile the page before rendering
try {
await this.hotReloader.ensurePage(pathname)
} catch (err) {
if (err.code === 'ENOENT') {
res.statusCode = 404
return this.renderErrorToHTML(null, req, res, pathname, query)
}
if (!this.quiet) console.error(err)
}
return super.renderToHTML(req, res, pathname, query)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册