Almost done!

This commit is contained in:
Jason 2022-02-23 15:04:25 -05:00
parent da5c0c88b1
commit 355e87dd21
13 changed files with 262 additions and 38 deletions

View file

@ -1,4 +1,5 @@
importScripts('/uv.bundle.js');
importScripts('/uv.config.js')
const csp = [
'cross-origin-embedder-policy',
@ -63,11 +64,7 @@ const statusCode = {
],
};
const handler = UVServiceWorker('/bare/', {
prefix: '/sw/',
encodeUrl: Ultraviolet.codec.xor.encode,
decodeUrl: Ultraviolet.codec.xor.decode,
});
const handler = UVServiceWorker(__uv$config.bare, __uv$config);
addEventListener('fetch', async event =>
event.respondWith(handler(event))
@ -204,7 +201,7 @@ function UVServiceWorker(bare = '/bare/', options) {
switch(request.destination) {
case 'script':
case 'worker':
responseCtx.body = `if (!self.__uv && self.importScripts) importScripts('/uv.bundle.js', '/uv.handler.js');\n`;
responseCtx.body = `if (!self.__uv && self.importScripts) importScripts('${__uv$config.bundle}', '${__uv$config.config}', '${__uv$config.handler}');\n`;
responseCtx.body += uv.js.rewrite(
await response.text()
);
@ -222,8 +219,9 @@ function UVServiceWorker(bare = '/bare/', options) {
{
document: true ,
injectHead: uv.createHtmlInject(
scripts.handler,
scripts.package,
options.handler,
options.bundle,
options.config,
uv.cookie.serialize(cookies, uv.meta, true),
request.referrer
)