Greg Bergé 10318b042e fix: fix module resolving
This issue fixes #59

It is possible to create a configuration which will result into a wrong state but it should not happen in 99.99% cases.
2018-05-12 16:09:44 +02:00

30 lines
742 B
JavaScript

import path from 'path'
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import express from 'express'
import { getLoadableState } from 'loadable-components/server'
import App from './App'
const app = express()
app.get('/', async (req, res) => {
try {
const reactApp = <App />
const loadableState = await getLoadableState(reactApp)
const html = ReactDOMServer.renderToString(reactApp)
res.send(`<!DOCTYPE html>
<html>
<body>
<div id="root">${html}</div>
${loadableState.getScriptTag()}
<script src="bundle.js"></script>
</body>
</html>`)
} catch (err) {
res.status(500)
res.send(err.stack)
}
})
app.listen(3000, () => console.log('http://localhost:3000'))