From 81ed0dae303f59f6404efa4c1417f9b5746d505b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 14 Jan 2023 16:09:19 -0500 Subject: [PATCH 1/2] Added fix for Analytics API 4 and Patch for Tetr.io over a reverse proxy / cloudflare argo tunnel --- app.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 13 deletions(-) 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 ] }); From 32f2395f9730925c1ba58d505d2e6c7d8128b0d6 Mon Sep 17 00:00:00 2001 From: MangoTornado <31556509+MangoTornado@users.noreply.github.com> Date: Sat, 14 Jan 2023 16:12:19 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 [![Deploy to Cyclic](https://deploy.cyclic.sh/button.svg)](https://deploy.cyclic.sh/) [![Deploy with Vercel](https://vercel.com/button)](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).