-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (41 loc) · 1.61 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server'),
config = require('./webpack.config.js');
// This was finished at 2016-12-09 21:15. Had one of the hard times with webpack.
// These are the times, where we hate open source.
// Now, here we have two servers running.
// 1 - WebpackDevServer for bundling assets or hot-reloading
// 2 - for serving other files
// The main server is express. It proxies to webpack-dev-server for bundles reactJS file
var path = require('path');
var express = require('express');
var proxy = require('proxy-middleware');
var url = require('url');
var bodyParser = require('body-parser');
var contentType = {
'.html': 'text/html',
'.css': "text/css",
'.js': 'application/javascript'
};
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(require('less-middleware')(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
// This is the place where bundle happens.
app.use('/dist', proxy(url.parse('http://localhost:3000/dist')));
app.use('/event/dist', proxy(url.parse('http://localhost:3000/dist')));
app.get('/*', function(req, res) {
// console.log(req.route);
res.setHeader('Content-Type',contentType);
res.sendFile(__dirname + '/indexDevelopment.html');
});
const PORT = process.env.PORT || 3000;
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
historyApiFallback: true
}).listen(PORT, function(err, result) {
if (err) console.log(err);
console.log('Listening at port '+ PORT);
});
app.listen(8080);