namesny-com/src/server.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-07-15 14:52:09 +00:00
require('babel-register');
var app = new (require('express'))()
var port = process.env.PORT || 3000;
require('css-modules-require-hook')({
generateScopedName: '[name]__[local]___[hash:base64:5]'
})
2017-04-09 19:09:27 +00:00
2017-07-15 14:52:09 +00:00
// initalize webpack dev middleware if in development context
if (process.env.NODE_ENV === 'development') {
var webpack = require('webpack')
var config = require('../webpack.config')
var devMiddleware = require('webpack-dev-middleware')
var hotDevMiddleware = require('webpack-hot-middleware')
var compiler = webpack(config)
var devMiddlewareConfig = {
noInfo: true,
stats: {colors: true},
publicPath: config.output.publicPath
2017-04-09 19:09:27 +00:00
}
2017-07-15 14:52:09 +00:00
app.use(devMiddleware(compiler, devMiddlewareConfig))
app.use(hotDevMiddleware(compiler))
}
app.use(require('express').static('public'))
2017-10-25 17:45:20 +00:00
var api = require('./api');
api(app);
2017-04-09 19:09:27 +00:00
2017-10-25 17:45:20 +00:00
var serverRender = require('./serverRender')
2017-07-15 14:52:09 +00:00
app.get("*", serverRender)
2017-04-09 19:09:27 +00:00
2017-07-15 14:52:09 +00:00
app.listen(port, function(error) {
if (error) {
console.error(error)
} else {
console.info("==> Listening on port %s", port)
2017-04-09 19:09:27 +00:00
}
2017-07-15 14:52:09 +00:00
})