-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
35 lines (30 loc) · 1.03 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// thank you
// http://ditrospecta.com/javascript/react/es6/webpack/heroku/2015/08/08/deploying-react-webpack-heroku.html
// for this code snippet
var express = require('express');
var path = require('path');
var webpack = require('webpack');
var app = express();
var isDevelopment = (process.env.NODE_ENV !== 'production');
console.log(isDevelopment);
var static_path = path.join(__dirname, 'public');
app.use(express.static(static_path))
.get('/', function (req, res) {
res.sendFile('index.html', {
root: static_path
});
}).listen(process.env.PORT || 8080, function (err) {
if (err) { console.log(err) };
console.log('Listening at localhost:8080');
});
if (isDevelopment) {
var config = require('./webpack.config');
var WebpackDevServer = require('webpack-dev-server');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true
}).listen(3030, 'localhost', function (err, result) {
if (err) { console.log(err) }
console.log('Listening at localhost:3030');
});
}