mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 03:50:02 -04:00
Heroku/Repl.it fix?
This commit is contained in:
parent
73cdcb3186
commit
2cbcaebca8
44 changed files with 1097 additions and 35748 deletions
34006
lib/server/bundle.js
34006
lib/server/bundle.js
File diff suppressed because one or more lines are too long
|
@ -13,6 +13,7 @@ const fs = require('fs');
|
|||
const defaultConfig = {
|
||||
prefix: '/service/',
|
||||
codec: 'plain',
|
||||
forceHttps: false,
|
||||
ws: true,
|
||||
cookie: true,
|
||||
title: 'Service',
|
||||
|
|
|
@ -13,12 +13,12 @@ function createRequestProxy(ctx) {
|
|||
const requestContext = {
|
||||
url: urlData.value,
|
||||
flags: urlData.flags,
|
||||
origin: (clientRequest.socket.encrypted ? 'https://' : 'http://') + clientRequest.headers.host,
|
||||
origin: ((clientRequest.socket.encrypted || ctx.config.forceHttps) ? 'https://' : 'http://') + clientRequest.headers.host,
|
||||
body: await getChunks(clientRequest),
|
||||
headers: { ...clientRequest.headers },
|
||||
method: clientRequest.method,
|
||||
rewrite: ctx,
|
||||
agent: new (urlData.value.protocol == 'https:' ? https : http).Agent({
|
||||
agent: new ((urlData.value.protocol == 'https:' || ctx.config.forceHttps) ? https : http).Agent({
|
||||
rejectUnauthorized: false,
|
||||
}),
|
||||
address: null,
|
||||
|
@ -27,7 +27,7 @@ function createRequestProxy(ctx) {
|
|||
};
|
||||
for (let i in ctx.config.requestMiddleware) ctx.config.requestMiddleware[i](requestContext);
|
||||
if (clientResponse.writableEnded) return;
|
||||
(requestContext.url.protocol == 'https:' ? https : http).request({
|
||||
((requestContext.url.protocol == 'https:' || ctx.config.forceHttps) ? https : http).request({
|
||||
headers: requestContext.headers,
|
||||
method: requestContext.method,
|
||||
hostname: requestContext.url.hostname,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*const route = [
|
||||
const route = [
|
||||
{
|
||||
types: ['text/html'],
|
||||
handler: 'html',
|
||||
|
@ -22,61 +22,15 @@ function rewriteBody(ctx) {
|
|||
|
||||
switch(data.handler) {
|
||||
case 'html':
|
||||
ctx.body = ctx.rewrite.html.process.bind(ctx.rewrite.html)(ctx.body.toString(), { meta, document: true });
|
||||
ctx.body = ctx.rewrite.html.process(ctx.body.toString(), { ...meta, document: true });
|
||||
break;
|
||||
case 'css':
|
||||
ctx.body = ctx.rewrite.css.process(ctx.body.toString(), { meta });
|
||||
ctx.body = ctx.rewrite.css.process(ctx.body.toString(), meta);
|
||||
break;
|
||||
case 'js':
|
||||
ctx.body = ctx.rewrite.js.process(ctx.body.toString(), ctx.url);
|
||||
break;
|
||||
};
|
||||
};
|
||||
*/
|
||||
|
||||
const map = [
|
||||
{
|
||||
condition: ctx => {
|
||||
if (!ctx.contentType && !ctx.extension) return false;
|
||||
if (ctx.contentType && !['application/javascript', 'application/x-javascript', 'text/javascript', 'text/x-javascript'].includes(ctx.contentType)) return false;
|
||||
if (ctx.extension != 'js') return false;
|
||||
return true;
|
||||
},
|
||||
run: (ctx) => ctx.rewrite.js.process(ctx.body.toString()),
|
||||
},
|
||||
{
|
||||
condition: ctx => {
|
||||
if (!ctx.contentType && !ctx.extension) return false;
|
||||
if (ctx.contentType && ctx.contentType != 'text/css') return false;
|
||||
if (ctx.extension != 'css') return false;
|
||||
return true;
|
||||
},
|
||||
run: (ctx, meta) => ctx.rewrite.css.process(ctx.body.toString(), { meta, }),
|
||||
},
|
||||
{
|
||||
condition: ctx => {
|
||||
if (ctx.contentType && ctx.contentType != 'text/html') return false;
|
||||
if (ctx.extension && !['html', 'htm'].includes(ctx.extension)) return false;
|
||||
return true;
|
||||
},
|
||||
run: (ctx, meta) => ctx.rewrite.html.process.bind(ctx.rewrite.html)(ctx.body.toString(), { meta, document: true })
|
||||
},
|
||||
];
|
||||
|
||||
function rewriteBody(ctx) {
|
||||
if (!ctx.body || !ctx.remoteResponse || ctx.flags.includes('xhr')) return;
|
||||
const meta = {
|
||||
base: ctx.url,
|
||||
origin: ctx.origin,
|
||||
};
|
||||
ctx.contentType = (ctx.headers['content-type'] || '').split(';')[0];
|
||||
ctx.extension = ctx.url.pathname.includes('.') ? ctx.url.pathname.split('.').slice(-1)[0] : '';
|
||||
for (const entry of map) {
|
||||
if (entry.condition(ctx, meta)) {
|
||||
ctx.body = entry.run(ctx, meta);
|
||||
break;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = rewriteBody;
|
|
@ -13,7 +13,7 @@ function createWebSocketProxy(ctx) {
|
|||
headers: { ...clientRequest.headers },
|
||||
method: clientRequest.method,
|
||||
rewrite: ctx,
|
||||
agent: new (urlData.value.protocol == 'https:' ? https : http).Agent({
|
||||
agent: new ((urlData.value.protocol == 'https:' || ctx.config.forceHttps) ? https : http).Agent({
|
||||
rejectUnauthorized: false,
|
||||
}),
|
||||
address: null,
|
||||
|
@ -22,7 +22,7 @@ function createWebSocketProxy(ctx) {
|
|||
clientHead,
|
||||
};
|
||||
ctx.config.requestMiddleware.forEach(fn => fn(requestContext));
|
||||
(requestContext.url.protocol == 'https:' ? https : http).request({
|
||||
((requestContext.url.protocol == 'https:' || ctx.config.forceHttps) ? https : http).request({
|
||||
headers: requestContext.headers,
|
||||
method: requestContext.method,
|
||||
hostname: requestContext.url.hostname,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue