-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
27 lines (23 loc) · 771 Bytes
/
index.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
var http = require('http');
var fs = require('fs');
var path = require('path');
var HOME = process.env.HOME || process.env.USERPROFILE;
function hostnameForRequest(req){
return req.headers['host'].split(':')[0];
}
var server = http.createServer(function(req, res){
console.log('connected to ' + req.headers['host'] + req.url);
fs.readFile(path.join(HOME, '.proxy.pac'), function(err, file){
if(err){
res.statusCode = 500;
return res.end(err.toString());
}
var contents = file.toString();
if(contents.indexOf('{hostname}')){
contents = contents.replace(/\{hostname\}/g, hostnameForRequest(req));
}
res.setHeader('Content-Type', 'application/x-ns-proxy-autoconfig');
res.end(contents);
});
});
server.listen(7799);