diff --git a/config/webpack.config.js b/config/webpack.config.js index 49e87da..7c95fd6 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -66,6 +66,8 @@ module.exports = function(projectRoot) { require.resolve('@babel/preset-react') ], filename: absoluteFrom, + comments: false, + minified: false }); return result.code; } diff --git a/package.json b/package.json index f817d15..99bf286 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "scripts": { "build": "babel src -d dist", + "watch": "babel src -d dist --watch", "test": "jest", "prepublishOnly": "npm run build" }, diff --git a/src/index.js b/src/index.js index e8b7dfa..58796d2 100644 --- a/src/index.js +++ b/src/index.js @@ -77,14 +77,11 @@ function bootstrapServer(options) { return res.render('404', { page: page }); } - // Read the file content - const fileContent = fs.readFileSync(handlerPath, 'utf8'); - - // Check for compiled React patterns - const isCompiledReact = /React\.createElement|_react2\.default/.test(fileContent); + var method = req.method.toLowerCase(); + var handler = require(handlerPath)(); - if (isCompiledReact) { - const reactElement = require(handlerPath).default; + if (handler.render && typeof handler.render === 'function' && method === 'get') { + const reactElement = handler.render(); const jsx = React.createElement(reactElement, {}); const jsxToHtml = ReactDOMServer.renderToString(jsx); @@ -94,9 +91,6 @@ function bootstrapServer(options) { return res.send(html); } - var handlerPath = path.join(process.cwd(), 'dist', 'routes', err.view.name + '.js'); - var handler = require(handlerPath)(); - if (!handler[req.method.toLowerCase()]) return res.render('404', { page: page }); return handler[req.method.toLowerCase()](req, res, next);