Created
August 24, 2017 12:38
-
-
Save jinglemansweep/5553c00911afe3ced6e96ba2fb2d7ee2 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 path from 'path'; | |
import express from 'express'; | |
import webpack from 'webpack'; | |
import webpackMiddleware from 'webpack-dev-middleware'; | |
import config from '../../webpack.config.js'; | |
import bodyParser from 'body-parser'; | |
import chalk from 'chalk'; | |
import helmet from 'helmet'; | |
import compression from 'compression'; | |
import PrettyError from 'pretty-error'; | |
import morgan from 'morgan'; | |
import 'better-log/install'; | |
const app = express(); | |
const env = process.env.NODE_ENV !== 'production' ? 'dev' : 'prod'; | |
const host = process.env.HOST || '0.0.0.0'; | |
const port = parseInt(process.env.PORT || '3456', 10); | |
const compiler = webpack(config(env)); | |
const pe = new PrettyError(); | |
pe.start(); | |
app.use(helmet()); | |
app.use(compression()); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(morgan('combined')); | |
app.use(express.static(__dirname + '../../dist')); | |
app.use(webpackMiddleware(compiler)); | |
app.get('*', function response(req, res) { | |
res.sendFile(path.join(__dirname, '../../dist/index.html')); | |
}); | |
app.listen( | |
port, host, | |
() => console.log(`Server running on ${chalk.green(host)}:${chalk.green(port)}`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment