-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (64 loc) · 1.94 KB
/
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
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
var http = require('http');
var request = require('request');
var fs = require('fs');
var domain = require('domain');
var index = fs.readFileSync('index.html');
var favicon = fs.readFileSync('favicon.ico');
var port = process.env.PORT || 8888;
var allowedOriginalHeaders = /^Date|Last-Modified|Expires|Cache-Control|Pragma|Content-Length|Content-Type|Access-Control-Allow/i;
var server = http.createServer(function (req, res) {
var d = domain.create();
d.on('error', function (e){
console.log('ERROR', e.stack);
res.statusCode = 500;
res.end('Error: ' + ((e instanceof TypeError) ? "make sure your URL is correct" : String(e)));
});
d.add(req);
d.add(res);
d.run(function() {
handler(req, res);
});
}).listen(port);
function handler(req, res) {
console.log(req.url);
switch (req.url) {
case "/":
res.writeHead(200);
res.write(index);
res.end();
break;
case "/index.html":
res.writeHead(200);
res.write(index);
res.end();
break;
case "/favicon.ico":
res.writeHead(200);
res.write(favicon);
res.end();
default:
if (req.url.indexOf('vivastreet') > -1 || req.url.indexOf('porn') > -1){
res.end('banned');
} else {
try {
res.setTimeout(25000);
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Credentials', false);
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
res.setHeader('Expires', new Date(Date.now() + 86400000).toUTCString()); // one day in the future
var r = request(req.url.slice(1).replace('googledriveproxy/', ''), {encoding: null, rejectUnauthorized: false});
r.pipefilter = function(response, dest) {
for (var header in response.headers) {
if (!allowedOriginalHeaders.test(header)) {
dest.removeHeader(header);
}
}
};
r.pipe(res);
} catch (e) {
res.end('Error: ' + ((e instanceof TypeError) ? "make sure your URL is correct" : String(e)));
}
}
}
}