-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (34 loc) · 1.13 KB
/
server.js
File metadata and controls
48 lines (34 loc) · 1.13 KB
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
var express = require('express'),
httpProxy = require('http-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 proxy_config = require('./proxy').proxy;
var default_proxy = { host: 'localhost', port: proxiedPort };
httpProxy.createServer(function (req, res, proxy) {
var target = {host:'localhost', port:proxiedPort};
var i = proxy_config.length,
config = {};
while(i--){
config = proxy_config[i];
if (req.url.match(new RegExp('^'+config.url,'i'))) {
target = { host:config.host, port:config.port};
req.url = req.url.slice(config.url.length);
console.log(req.url);
break;
}
}
proxy.proxyRequest(req, res, target);
}).listen(port);
};