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

Move ensurePage to DevServer (#5582)

It's no longer needed inside the `render()` function since we have a separate devServer
This commit is contained in:
Tim Neutkens 2018-11-03 01:24:43 +01:00 committed by GitHub
parent 1496ad6299
commit a1bdbad2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View file

@ -24,8 +24,6 @@ function getDynamicImportBundles (manifest, moduleIds) {
}, []) }, [])
} }
const logger = console
// since send doesn't support wasm yet // since send doesn't support wasm yet
send.mime.define({ 'application/wasm': ['wasm'] }) send.mime.define({ 'application/wasm': ['wasm'] })
@ -63,7 +61,6 @@ async function doRender (req, res, pathname, query, {
err, err,
page, page,
buildId, buildId,
hotReloader,
assetPrefix, assetPrefix,
runtimeConfig, runtimeConfig,
distDir, distDir,
@ -74,11 +71,6 @@ async function doRender (req, res, pathname, query, {
} = {}) { } = {}) {
page = page || pathname 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 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') const appPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_app')
let [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([ let [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([
@ -203,7 +195,7 @@ export async function renderScriptError (req, res, page, error) {
return return
} }
logger.error(error.stack) console.error(error.stack)
res.statusCode = 500 res.statusCode = 500
res.end('500 - Internal Error') res.end('500 - Internal Error')
} }

View file

@ -8,7 +8,6 @@ export default class DevServer extends Server {
constructor (options) { constructor (options) {
super(options) super(options)
this.hotReloader = new HotReloader(this.dir, { config: this.nextConfig, buildId: this.buildId }) this.hotReloader = new HotReloader(this.dir, { config: this.nextConfig, buildId: this.buildId })
this.renderOpts.hotReloader = this.hotReloader
this.renderOpts.dev = true this.renderOpts.dev = true
} }
@ -90,6 +89,17 @@ export default class DevServer extends Server {
return this.renderErrorToHTML(compilationErr, req, res, pathname, query) 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) return super.renderToHTML(req, res, pathname, query)
} }