update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / project_management / server.js
1 /*
2 * STANDARD_RIFT_IO_COPYRIGHT
3 */
4
5 var express = require('express');
6 var path = require('path');
7 var httpProxy = require('http-proxy');
8 var bodyParser = require('body-parser');
9 var cors = require('cors');
10 var session = require('express-session');
11 var proxy = httpProxy.createProxyServer();
12 var app = express();
13
14 var isProduction = process.env.NODE_ENV === 'production';
15 var port = isProduction ? 8080 : 8888;
16 var publicPath = path.resolve(__dirname, 'public');
17
18 if (!isProduction) {
19
20 //Routes for local development
21 var lpRoutes = require('./routes.js');
22
23 app.use(express.static(publicPath));
24 app.use(session({
25 secret: 'ritio rocks',
26 }));
27 app.use(bodyParser.urlencoded({
28 extended: true
29 }));
30 app.use(bodyParser.json());
31 app.use(cors());
32 app.use('/', lpRoutes);
33 var bundle = require('./server/bundle.js');
34 bundle();
35
36 app.all('/build/*', function (req, res) {
37 proxy.web(req, res, {
38 target: 'http://localhost:8080'
39 });
40 });
41
42 }
43 proxy.on('error', function(e) {
44 console.log('Could not connect to proxy, please try again...');
45 });
46
47 app.listen(port, function () {
48 console.log('Server running on port ' + port);
49 });
50
51 app.get('/*')