Commit fa03f0b9 authored by Tim Neutkens's avatar Tim Neutkens Committed by Arunoda Susiripala

Require files directly instead of resolving them (#3683)

parent ed122934
...@@ -4,7 +4,6 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server' ...@@ -4,7 +4,6 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import send from 'send' import send from 'send'
import generateETag from 'etag' import generateETag from 'etag'
import fresh from 'fresh' import fresh from 'fresh'
import requireModule from './require'
import getConfig from './config' import getConfig from './config'
import { Router } from '../lib/router' import { Router } from '../lib/router'
import { loadGetInitialProps, isResSent } from '../lib/utils' import { loadGetInitialProps, isResSent } from '../lib/utils'
...@@ -55,10 +54,17 @@ async function doRender (req, res, pathname, query, { ...@@ -55,10 +54,17 @@ async function doRender (req, res, pathname, query, {
const pagePath = join(dir, dist, 'dist', 'bundles', 'pages', page) const pagePath = join(dir, dist, 'dist', 'bundles', 'pages', page)
const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document') const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document')
let [Component, Document] = await Promise.all([ let Component
requireModule(pagePath), let Document
requireModule(documentPath) try {
]) Component = require(pagePath)
Document = require(documentPath)
} catch (err) {
const err = new Error(`Cannot find module`)
err.code = 'ENOENT'
throw err
}
Component = Component.default || Component Component = Component.default || Component
Document = Document.default || Document Document = Document.default || Document
const asPath = req.url const asPath = req.url
......
import resolve from './resolve'
export default async function requireModule (path) {
const f = await resolve(path)
return require(f)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment