Last active
April 8, 2018 00:04
-
-
Save faceyspacey/0c6e1aa59e7502ef60a0442d9e814ae4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express' | |
import routes from './routes'; | |
import { render, build } from 'react-universal-starter'; | |
const app = express(); | |
const handler = build(async (req, res, stats) => { | |
try { | |
const html = await render(routes, stats); | |
res.send(html); | |
} catch (error) { | |
res.json(error); | |
} | |
}) | |
app.get('/*', handler) | |
// build.js | |
export default (callback) => { | |
const compiler = webpack([clientConfig, serverConfig]) | |
const hotServerMw = webpackHotServerMiddleware(compiler) | |
const compressionMw = compression() | |
return (req, res, next) => { | |
compressionMw(req, res, next) // this may or may not be the correct usage, but it's the blueprint of what must be done | |
const stats = hotServerMw(req, res, next) // we're gonna have to modify how webpackHotServerMiddleware works | |
if (stats) return callback(req, res, next, stats) | |
throw new Error('stats not ready yet') // you get the idea -- `hotServerMw` will return the stats every time it's called after the build is completed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment