-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.js
More file actions
56 lines (52 loc) · 1.4 KB
/
Copy pathproxy.js
File metadata and controls
56 lines (52 loc) · 1.4 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
49
50
51
52
53
54
55
56
/**
* Medici
* Copyright (c) 2012 Kristoffer Andersen
* All right reserved
*
* This file contains a server redirect proxy.
* It can route incomming HTTP Requests on one listening port
* to several other ports. This allows you to run a node.js server on port 8080
* and a lighttpd server on 88. This proxy will listen on port 80, and route
* requests to either based on the HOST request header. (like virtual hosts).
* Should you choose to use this application, then change this host name in
* line 22.
*/
var n = {
http : require('http')
};
var server = n.http.createServer(function(req, res){
var pReq = null;
if (req.headers.host == 'subdomain.yourhost.com') {
pReq = n.http.request({
host: 'localhost',
port: 8080,
method: req.method,
path: req.url,
headers: req.headers
},function(pRes){
res.writeHead(pRes.statusCode, pRes.headers);
pRes.pipe(res);
});
}
else {
pReq = n.http.request({
host: 'localhost',
port: 88,
method: req.method,
path: req.url,
headers: req.headers
},function(pRes){
res.writeHead(pRes.statusCode, pRes.headers);
pRes.pipe(res);
});
}
var d = new Date();
console.log(d.toString()+" proxy: "+req.method+" "+req.headers.host+req.url+" ("+req.headers['user-agent']+")");
req.on ('close',function(){
pReq.abort();
});
pReq.on('close',function(){req.abort();});
req.pipe(pReq);
});
server.listen(80);
console.log("Proxy started...");