Merge "Fix problem with top level choice elements not being saved correctly. - create...
[osm/UI.git] / skyquake / plugins / logging / server.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 var express = require('express');
20 var path = require('path');
21 var httpProxy = require('http-proxy');
22 var bodyParser = require('body-parser');
23 var cors = require('cors');
24 var session = require('express-session');
25 var proxy = httpProxy.createProxyServer();
26 var app = express();
27
28 var isProduction = process.env.NODE_ENV === 'production';
29 var port = isProduction ? 8080 : 8888;
30 var publicPath = path.resolve(__dirname, 'public');
31
32 if (!isProduction) {
33
34 //Routes for local development
35 var lpRoutes = require('./routes.js');
36
37 app.use(express.static(publicPath));
38 app.use(session({
39 secret: 'ritio rocks',
40 }));
41 app.use(bodyParser.urlencoded({
42 extended: true
43 }));
44 app.use(bodyParser.json());
45 app.use(cors());
46 app.use('/', lpRoutes);
47 var bundle = require('./server/bundle.js');
48 bundle();
49
50 app.all('/build/*', function (req, res) {
51 proxy.web(req, res, {
52 target: 'http://localhost:8080'
53 });
54 });
55
56 }
57 proxy.on('error', function(e) {
58 console.log('Could not connect to proxy, please try again...');
59 });
60
61 app.listen(port, function () {
62 console.log('Server running on port ' + port);
63 });