diff --git a/README.md b/README.md index c69d1d4..188571f 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,18 @@ The original nodeunblocker.com is gone, but it's now easier than ever to deploy [](https://deploy.cyclic.sh/) [](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fnfriedly%2Fnodeunblocker.com) +## Now with tetr.io support + +Added a fix for tetr.io when running over reverse proxy or any tunneling service + +To disable it just add `//` to the beginning of [this line of code in app.js](https://github.com/nfriedly/nodeunblocker.com/blob/5355bbfa8cfe2b5d2e6e5aae41ea21936a3be9a5/app.js#L106) like so: + +```js +// tetrioPatch +``` + +Also fixed Analytics Api to newest Analytics 4 + ## Now with YouTube support (sort of) I went ahead and activated the [youtube example](https://github.com/nfriedly/node-unblocker/blob/master/examples/youtube/youtube.js), it replaces youtube.com video pages with a custom page that just streams the video (but actually works). diff --git a/app.js b/app.js index 655a3ac..0994224 100644 --- a/app.js +++ b/app.js @@ -23,18 +23,17 @@ var google_analytics_id = process.env.GA_ID || null; function addGa(html) { if (google_analytics_id) { var ga = [ - "" - ].join("\n"); - html = html.replace("
", ga + "\n\n"); + "", + "", + "" + ].join("\n"); + html = html.replace("
", "
\n\n" + ga); } return html; } @@ -53,13 +52,58 @@ function googleAnalyticsMiddleware(data) { } } +function forceUpgrade(html) { + var meta = [ + "" + ].join("\n"); + html = html.replace("", meta + "\n\n"); + return html; +} + +function forceHttpsUpgradeMiddleware(data) { + if (data.contentType == 'text/html') { + + // https://nodejs.org/api/stream.html#stream_transform + data.stream = data.stream.pipe(new Transform({ + decodeStrings: false, + transform: function(chunk, encoding, next) { + this.push(forceUpgrade(chunk.toString())); + next(); + } + })); + } +} + +function tetrioPatch(html) { + var meta = [ + "" + ].join("\n"); + html = html.replace("", "\n\n" + meta); + return html; +} + +function tetrioPatchMiddleware(data) { + if (data.contentType == 'text/html') { + + // https://nodejs.org/api/stream.html#stream_transform + data.stream = data.stream.pipe(new Transform({ + decodeStrings: false, + transform: function(chunk, encoding, next) { + this.push(tetrioPatch(chunk.toString())); + next(); + } + })); + } +} + var unblocker = new Unblocker({ prefix: '/proxy/', requestMiddleware: [ youtube.processRequest ], responseMiddleware: [ - googleAnalyticsMiddleware + googleAnalyticsMiddleware, + tetrioPatch ] });