mirror of
https://github.com/NebulaServices/Nebula.git
synced 2025-05-13 12:00:01 -04:00
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
importScripts("/uv/uv.bundle.js");
|
|
importScripts("/uv/uv.config.js");
|
|
importScripts(__uv$config.sw || "/uv/uv.sw.js");
|
|
importScripts("/dynamic/dynamic.config.js");
|
|
importScripts("/dynamic/dynamic.worker.js");
|
|
//import our IDB lib
|
|
importScripts("/localforage/localforage.min.js");
|
|
localforage.config({
|
|
driver: localforage.INDEXEDDB,
|
|
name: "Nebula",
|
|
version: 1.0,
|
|
storeName: "nebula_config",
|
|
description: "Nebula Config for things reliant on IndexedDB"
|
|
});
|
|
|
|
const dynPromise = new Promise(async (resolve) => {
|
|
try {
|
|
const bare =
|
|
(await localforage.getItem("bare")) || location.origin + "/bare/";
|
|
self.__dynamic$config.bare.path = bare;
|
|
self.dynamic = new Dynamic(self.__dynamic$config);
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
resolve();
|
|
});
|
|
|
|
const uvPromise = new Promise(async (resolve) => {
|
|
try {
|
|
const bare =
|
|
(await localforage.getItem("bare")) || location.origin + "/bare/";
|
|
self.__uv$config.bare = bare;
|
|
self.uv = new UVServiceWorker(self.__uv$config);
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
resolve();
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
if (
|
|
event.request.url.startsWith(location.origin + self.__dynamic$config.prefix)
|
|
) {
|
|
event.respondWith(
|
|
(async function () {
|
|
try {
|
|
await dynPromise;
|
|
} catch (error) {}
|
|
if (await self.dynamic.route(event)) {
|
|
return await self.dynamic.fetch(event);
|
|
}
|
|
await fetch(event.request);
|
|
})()
|
|
);
|
|
} else if (
|
|
event.request.url.startsWith(location.origin + self.__uv$config.prefix)
|
|
) {
|
|
event.respondWith(
|
|
(async function () {
|
|
try {
|
|
await uvPromise;
|
|
} catch (error) {}
|
|
return await self.uv.fetch(event);
|
|
})()
|
|
);
|
|
}
|
|
});
|