-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (32 loc) · 1.3 KB
/
app.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
var url = require('url');
var querystring = require('querystring');
var express = require('express');
var Unblocker = require('unblocker');
var Transform = require('stream').Transform;
var youtube = require('unblocker/examples/youtube/youtube.js')
var app = express();
var google_analytics_id = process.env.GA_ID || null;
var unblocker = new Unblocker({
prefix: '/proxy/',
requestMiddleware: [
youtube.processRequest
],
responseMiddleware: [
googleAnalyticsMiddleware
]
});
// this line must appear before any express.static calls (or anything else that sends responses)
app.use(unblocker);
// serve up static files *after* the proxy is run
app.use('/', express.static(__dirname + '/public'));
// this is for users who's form actually submitted due to JS being disabled or whatever
app.get("/no-js", function(req, res) {
// grab the "url" parameter from the querystring
var site = querystring.parse(url.parse(req.url).query).url;
// and redirect the user to /proxy/url
res.redirect(unblockerConfig.prefix + site);
});
const port = process.env.PORT || process.env.VCAP_APP_PORT || 8080;
app.listen(port, function() {
console.log(`node unblocker process listening at http://localhost:${port}/`);
}).on("upgrade", unblocker.onUpgrade); // onUpgrade handles websockets