mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
This reverts commit fa03f0b9cc
.
This commit is contained in:
parent
fa03f0b9cc
commit
8308a33c11
|
@ -4,6 +4,7 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server'
|
|||
import send from 'send'
|
||||
import generateETag from 'etag'
|
||||
import fresh from 'fresh'
|
||||
import requireModule from './require'
|
||||
import getConfig from './config'
|
||||
import { Router } from '../lib/router'
|
||||
import { loadGetInitialProps, isResSent } from '../lib/utils'
|
||||
|
@ -54,17 +55,10 @@ async function doRender (req, res, pathname, query, {
|
|||
const pagePath = join(dir, dist, 'dist', 'bundles', 'pages', page)
|
||||
const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document')
|
||||
|
||||
let Component
|
||||
let Document
|
||||
try {
|
||||
Component = require(pagePath)
|
||||
Document = require(documentPath)
|
||||
} catch (err) {
|
||||
const err = new Error(`Cannot find module`)
|
||||
err.code = 'ENOENT'
|
||||
throw err
|
||||
}
|
||||
|
||||
let [Component, Document] = await Promise.all([
|
||||
requireModule(pagePath),
|
||||
requireModule(documentPath)
|
||||
])
|
||||
Component = Component.default || Component
|
||||
Document = Document.default || Document
|
||||
const asPath = req.url
|
||||
|
|
6
server/require.js
Normal file
6
server/require.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import resolve from './resolve'
|
||||
|
||||
export default async function requireModule (path) {
|
||||
const f = await resolve(path)
|
||||
return require(f)
|
||||
}
|
Loading…
Reference in a new issue