-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemoserver.js
92 lines (63 loc) · 2.24 KB
/
demoserver.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var express = require('express')
, http = require('http')
, path = require('path')
, ioSocket = require('socket.io')
, passport = require('passport')
, httpProxy = require('http-proxy')
, cors = require('cors')
, orionInit = require('./orion/modules/orionode/orionServer');
if (!orionInit) throw "can't find orion";
if(process.argv[2] == '-production')
process.env['environment'] = 'prod';
else
process.env['environment'] = 'dev'
var app = express();
var orion = orionInit(app);
var proxy = httpProxy.createProxyServer({});
var proxyInit = function(req, res){
// Remove '/api' part from query string
console.log("req url " + req.url);
var routerKey = req.url.split('/').slice(1, 2).join();
console.log(routerKey);
if ( routerKey === 'codefresh')
{
req.url = '/' + req.url.split('/').slice(2).join('/');
console.log("target url " + req.url );
// Create proxy
proxy.web(req, res, { target: "http://localhost:8000"});
return;
}else {
// Create proxy
proxy.web(req, res, { target: "http://localhost:8081"})
return;
}
} ;
app.use(express.logger({format: 'dev'}));
app.use(express.json());
app.use(express.urlencoded());
//app.use(express.multipart());
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'app')));
app.use(express.static(path.join(__dirname, 'demoserver/templates')));
app.use( express.cookieParser() );
app.use( cors() );
app.use(express.session({secret: 'keyboard cat' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(function(err, req, res, next){
//return error default
throw err
});
app.set('port', process.env.PORT || 8000);
var server = http.createServer(app);
server.listen(app.get('port'), function(){
var io = ioSocket.listen(server);
io.set('log level', 1);
io.emit("test", {"test" : "oleg"});
require('./server/routes.js')(app, io);
console.log("Express server listening on port " + app.get('port'));
console.log("start date is " + new Date());
//console.log(app.routes);
});
exports.app = app;