forked from cancerregulome/GeneSpot_1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·67 lines (53 loc) · 1.87 KB
/
server.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
var express = require("express");
var httpProxy = require("http-proxy");
var configuration = require("./proxy");
exports.startServer = function(port, path) {
var app = express();
// Configuration
app.configure(function() {
app.use(express.static(__dirname + "/_public"));
});
app.configure("development", function() {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure("production", function() {
app.use(express.errorHandler());
});
var proxiedPort = port + 1;
app.listen(proxiedPort);
var proxyConfigurations = configuration.proxy;
var getMatchingConfig = function(req) {
for (var i = 0; i < proxyConfigurations.length; i++) {
var config = proxyConfigurations[i];
if (req.url.match(new RegExp("^" + config.url, "i"))) {
return config;
}
}
return null;
};
httpProxy.createServer(
function (req, res, proxy) {
var target = {
"host":"localhost",
"port":proxiedPort
};
var proxyConfig = getMatchingConfig(req);
if (proxyConfig) {
target["host"] = proxyConfig.host;
target["port"] = proxyConfig.port;
if (proxyConfig.rewrite_url) {
if (!proxyConfig.keep_url) {
req.url = req.url.slice(proxyConfig.url.length);
}
req.url = proxyConfig.rewrite_url + req.url;
proxy.proxyRequest(req, res, target);
return;
}
if (!proxyConfig.keep_url) {
req.url = req.url.slice(proxyConfig.url.length);
}
}
proxy.proxyRequest(req, res, target);
}
).listen(port);
};