-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.js
48 lines (26 loc) · 920 Bytes
/
proxy.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
var proxy = require('http-proxy').createProxyServer({});
var hostconfig = require('./hostconfig.json');
proxy.on(function(err, req, res) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
});
var server = require('http').createServer(function(req, res) {
var host = req.headers.host;
var hostaddr = 'http://localhost:' + hostconfig.hostport
switch (host) {
case 'www.yourdomain.com':
proxy.web(req, res, { target: hostaddr });
break;
case 'yourdomain.com':
proxy.web(req, res, { target: hostaddr });
break;
default:
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('Welcome to my server!');
}
});
console.log("listening on port 80")
server.listen(80);