Added Corrosion Fix for Heroku

Credits: https://github.com/BinBashBanana/Corrosion-Heroku (very epic person)
This commit is contained in:
TheEmeraldStarr 2021-11-29 23:40:38 -08:00
parent 8d88daf1c2
commit b0c48df26c
25 changed files with 13 additions and 10 deletions

View file

@ -1,36 +0,0 @@
const route = [
{
types: ['text/html'],
handler: 'html',
},
{
types: ['text/css'],
handler: 'css',
},
{
types: ['application/javascript', 'application/x-javascript', 'text/javascript', 'text/x-javascript'],
handler: 'js',
},
]
function rewriteBody(ctx) {
if (!ctx.body || !ctx.remoteResponse || ctx.flags.includes('xhr')) return;
const meta = {
base: ctx.url,
origin: ctx.origin,
};
const data = route.find(entry => ctx.flags == entry.handler) || route.find(entry => entry.types.includes((ctx.headers['content-type'] || '').split(';')[0])) || {};
switch(data.handler) {
case 'html':
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);
break;
case 'js':
ctx.body = ctx.rewrite.js.process(ctx.body.toString(), ctx.url);
break;
};
};
module.exports = rewriteBody;