Some updates!

This commit is contained in:
QuiteAFancyEmerald 2021-11-29 22:02:24 -08:00
parent 47a843bbb8
commit df4ce2ae68
No known key found for this signature in database
GPG key ID: 14E10C9F7DC07318
1412 changed files with 188615 additions and 149532 deletions

View file

@ -0,0 +1,36 @@
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;