Skip to content

Commit

Permalink
Fix Aero
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebelung-Dev committed Mar 17, 2023
1 parent d1e8eea commit 31c9ac5
Show file tree
Hide file tree
Showing 17 changed files with 2,090 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- [x] Obfuscate more text

### Upcoming
- [x] Fix Aero
- [x] Update docs
- [ ] Add a blocklist option
- [ ] Reset all settings
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 26 additions & 25 deletions public/aero/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function handle(event) {
const afterPrefix = url =>
url.replace(new RegExp(`^(${location.origin}${prefix})`, "g"), "");

const useBare = BareClient;
const useBare = BareClient || typeof BareClient === "function";

// Construct proxy fetch instance
const proxyFetch = useBare
Expand Down Expand Up @@ -132,7 +132,7 @@ async function handle(event) {
}

// Get the cache age before we start rewriting
let cacheAge = cache.getAge(
const cacheAge = cache.getAge(
reqHeaders["cache-control"],
reqHeaders["expires"]
);
Expand Down Expand Up @@ -178,10 +178,6 @@ async function handle(event) {
respHeaders
);

// Backup headers to later conceal in http request api interceptors
if (req.destination === "")
rewriteGetCookie["x-aero-headers"] = JSON.stringify(respHeaders);

const type = respHeaders["content-type"];

const html =
Expand Down Expand Up @@ -214,9 +210,7 @@ async function handle(event) {
-->
<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon">
<!-- If not defined already, manually set the favicon -->
<link href="${
prefix + proxyUrl.origin
}/favicon.ico" rel="icon" type="image/x-icon">
<link href="/favicon.ico" rel="icon" type="image/x-icon">
<script>
// Update the service worker
Expand All @@ -232,32 +226,40 @@ async function handle(event) {
.catch(err => console.error(err.message));
// Aero's global namespace
var $aero = {
config: {
prefix: "${prefix}",
wsBackends: ${JSON.stringify(wsBackends)},
wrtcBackends: ${JSON.stringify(wrtcBackends)},
debug: ${JSON.stringify(debug)},
flags: ${JSON.stringify(flags)},
},
cors: ${JSON.stringify(injectHeaders)},
// This is used to later copy into an iFrame's srcdoc; this is for an edge case
imports: \`${unwrapImports(routes, true)}\`,
afterPrefix: url => url.replace(new RegExp(\`^(\${location.origin}\${$aero.config.prefix})\`, "g"), ""),
};
Object.defineProperty(window, "$aero", {
value: {
config: {
prefix: "${prefix}",
wsBackends: ${JSON.stringify(wsBackends)},
wrtcBackends: ${JSON.stringify(wrtcBackends)},
debug: ${JSON.stringify(debug)},
flags: ${JSON.stringify(flags)},
},
useBare: ${useBare},
cors: ${JSON.stringify(injectHeaders)},
// This is used to later copy into an iFrame's srcdoc; this is for an edge case
imports: \`${unwrapImports(routes, true)}\`,
afterPrefix: url => url.replace(new RegExp(\`^(\${location.origin}\${$aero.config.prefix})\`, "g"), ""),
},
writable: false
});
Object.freeze($aero.config);
</script>
<script>
// Sanity check
if (!("$aero" in window)) {
// Clear site
document.head.innerHTML = "";
document.write("Unable to initalize $aero");
document.write("<h1>Unable to initalize $aero</h1>");
}
</script>
<!-- Injected Aero code -->
${unwrapImports(routes)}
<script>
Object.freeze($aero);
</script>
</head>
${body}
`;
Expand Down Expand Up @@ -302,7 +304,6 @@ ${body}
// Exit script
if (blocked)
// TODO: Error emulation
throw new Error("Script blocked")
}
})();
Expand Down Expand Up @@ -383,4 +384,4 @@ ${body}
return proxyResp;
}

export default handle;
export default handle;
Loading

0 comments on commit 31c9ac5

Please sign in to comment.