-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
69 lines (61 loc) · 1.71 KB
/
main.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
var http = require('http'),
httpProxy = require('http-proxy'),
proxy = httpProxy.createProxyServer({}),
url = require('url');
http.createServer(function (req, res) {
var hostname, pathname;
if (!req.headers.host) {
console.log('no host in headers', req.headers);
} else {
hostname = req.headers.host.split(":")[0];
}
pathname = url.parse(req.url).pathname;
console.log('====================================');
console.log('CONNECTION: ', new Date().toString());
console.log('headers: ', req.headers);
console.log('hostname: ', hostname);
console.log('pathname: ', pathname);
console.log('====================================');
// TODO: pull ports from config
switch (hostname) {
case 'dev.server.ironbane.com':
proxy.web(req, res, {
target: 'http://localhost:5001'
});
break;
case 'play.server.ironbane.com':
proxy.web(req, res, {
target: 'http://localhost:3100'
});
break;
default:
proxy.web(req, res, {
target: 'http://localhost:3100'
});
}
}).listen(8080, function () {
console.log('proxy listening on port 8080');
});
var exitHandler = function (options, err) {
if (options.cleanup) {
console.log('clean');
}
if (err) {
console.log(err.stack);
}
if (options.exit) {
process.exit();
}
};
//do something when app is closing
process.on('exit', exitHandler.bind(null, {
cleanup: true
}));
//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {
exit: true
}));
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: false
}));