Skip to content

Instantly share code, notes, and snippets.

@cef62
Forked from maman/server.js
Last active November 17, 2015 17:22
Show Gist options
  • Save cef62/955081fd942437a42231 to your computer and use it in GitHub Desktop.
Save cef62/955081fd942437a42231 to your computer and use it in GitHub Desktop.
HTML5 API support con webpack-dev-middleware and index.html dynamically generated
/*eslint-disable */
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require(path.join(__dirname, 'webpack.config'));
var app = this.app = new express();
var compiler = webpack(config);
var devMiddleware = require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
})
/*eslint-enable */
app.use(this.middleware = devMiddleware);
app.use(require('webpack-hot-middleware')(compiler));
app.get('*', function(req, res) {
/*eslint-disable */
var index = this.middleware.fileSystem.readFileSync(path.join(config.output.path, 'index.html'));
/*eslint-enable */
res.end(index);
}.bind(this));
app.listen(3001, 'localhost', function(err) {
if (err) {
console.log('err');
return;
}
console.log('Listening at http://localhost:3001');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment