Feat: proxy

This commit is contained in:
MotorTruck1221
2025-03-23 21:39:32 -06:00
parent a0baded584
commit 2cfdf7fbae
10 changed files with 260 additions and 11 deletions
+27
View File
@@ -0,0 +1,27 @@
importScripts(
"/vu/uv.bundle.js",
"/vu/uv.config.js",
"/marcs/scramjet.shared.js",
"/marcs/scramjet.worker.js"
);
importScripts(__uv$config.sw || "/vu/uv.sw.js");
const uv = new UVServiceWorker();
const sj = new ScramjetServiceWorker();
self.addEventListener("fetch", function (event) {
event.respondWith(
(async () => {
await sj.loadConfig();
if (event.request.url.startsWith(location.origin + __uv$config.prefix)) {
return await uv.fetch(event);
}
else if (sj.route(event)) {
return await sj.fetch(event);
}
else {
return await fetch(event.request);
}
})()
);
});
+29
View File
@@ -0,0 +1,29 @@
self.__uv$config = {
prefix: "/~/uv/",
encodeUrl: function encode(str) {
if (!str) return str;
return encodeURIComponent(
str
.toString()
.split("")
.map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt() ^ 3) : char))
.join("")
);
},
decodeUrl: function decode(str) {
if (!str) return str;
let [input, ...search] = str.split("?");
return (
decodeURIComponent(input)
.split("")
.map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt(0) ^ 3) : char))
.join("") + (search.length ? "?" + search.join("?") : "")
);
},
handler: "/vu/uv.handler.js",
client: "/vu/uv.client.js",
bundle: "/vu/uv.bundle.js",
config: "/vu/uv.config.js",
sw: "/vu/uv.sw.js"
};