forked from nfriedly/node-unblocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (27 loc) · 894 Bytes
/
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
"use strict";
var http = require("http");
var Unblocker = require("unblocker");
var unblocker = Unblocker({});
http
.createServer(function(req, res) {
// first let unblocker try to handle the requests
unblocker(req, res, function(err) {
// this callback will be fired for any request that unblocker does not serve
var headers = { "content-type": "text/plain" };
if (err) {
res.writeHead(500, headers);
return res.end(err.stack || err);
}
if (req.url == "/") {
res.writeHead(200, headers);
return res.end(
"Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy."
);
} else {
res.writeHead(404, headers);
return res.end("Error 404: file not found.");
}
});
})
.listen(8080);
console.log("proxy server live at http://localhost:8080/");