Skip to content

Commit

Permalink
Revert "Require files directly instead of resolving them (#3683)" (#3684
Browse files Browse the repository at this point in the history
)

This reverts commit fa03f0b.
  • Loading branch information
arunoda committed Feb 5, 2018
1 parent fa03f0b commit 8308a33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 5 additions & 11 deletions server/render.js
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions server/require.js
@@ -0,0 +1,6 @@
import resolve from './resolve'

export default async function requireModule (path) {
const f = await resolve(path)
return require(f)
}

0 comments on commit 8308a33

Please sign in to comment.