Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.0-alpha.4 #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ module.exports = function(projectRoot) {
require.resolve('@babel/preset-react')
],
filename: absoluteFrom,
comments: false,
minified: false
});
return result.code;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"scripts": {
"build": "babel src -d dist",
"watch": "babel src -d dist --watch",
"test": "jest",
"prepublishOnly": "npm run build"
},
Expand Down
14 changes: 4 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down