X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fplugins%2Flogging%2Fserver.js;fp=skyquake%2Fplugins%2Flogging%2Fserver.js;h=03b53fb0e7c67335745e1b7ea4f772b8e6cdf4ec;hb=e29efc315df33d546237e270470916e26df391d6;hp=0000000000000000000000000000000000000000;hpb=9c5e457509ba5a1822c316635c6308874e61b4b9;p=osm%2FUI.git diff --git a/skyquake/plugins/logging/server.js b/skyquake/plugins/logging/server.js new file mode 100644 index 000000000..03b53fb0e --- /dev/null +++ b/skyquake/plugins/logging/server.js @@ -0,0 +1,63 @@ +/* + * + * Copyright 2016 RIFT.IO Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +var express = require('express'); +var path = require('path'); +var httpProxy = require('http-proxy'); +var bodyParser = require('body-parser'); +var cors = require('cors'); +var session = require('express-session'); +var proxy = httpProxy.createProxyServer(); +var app = express(); + +var isProduction = process.env.NODE_ENV === 'production'; +var port = isProduction ? 8080 : 8888; +var publicPath = path.resolve(__dirname, 'public'); + +if (!isProduction) { + + //Routes for local development + var lpRoutes = require('./routes.js'); + + app.use(express.static(publicPath)); + app.use(session({ + secret: 'ritio rocks', + })); + app.use(bodyParser.urlencoded({ + extended: true + })); + app.use(bodyParser.json()); + app.use(cors()); + app.use('/', lpRoutes); + var bundle = require('./server/bundle.js'); + bundle(); + + app.all('/build/*', function (req, res) { + proxy.web(req, res, { + target: 'http://localhost:8080' + }); + }); + +} +proxy.on('error', function(e) { + console.log('Could not connect to proxy, please try again...'); +}); + +app.listen(port, function () { + console.log('Server running on port ' + port); +});