a
This commit is contained in:
parent
070295ab3b
commit
16aecc05f6
3 changed files with 14 additions and 2 deletions
|
|
@ -17,6 +17,10 @@ async function __uvHook(window, config = {}, bare = '/bare/') {
|
|||
window,
|
||||
});
|
||||
|
||||
if (typeof config.construct === 'function') {
|
||||
config.construct(__uv, worker ? 'worker' : 'window');
|
||||
};
|
||||
|
||||
const { client } = __uv;
|
||||
const {
|
||||
HTMLMediaElement,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
importScripts('./uv.sw.js');
|
||||
|
||||
const sw = new UVServiceWorker();
|
||||
|
||||
self.addEventListener('fetch', event =>
|
||||
event.respondWith(
|
||||
sw.fetch(event)
|
||||
|
|
|
|||
11
lib/uv.sw.js
11
lib/uv.sw.js
|
|
@ -54,6 +54,11 @@ class UVServiceWorker extends EventEmitter {
|
|||
try {
|
||||
|
||||
const ultraviolet = new Ultraviolet(this.config);
|
||||
|
||||
if (typeof this.config.construct === 'function') {
|
||||
this.config.construct(ultraviolet, 'service');
|
||||
};
|
||||
|
||||
const db = await ultraviolet.cookie.db();
|
||||
|
||||
ultraviolet.meta.origin = location.origin;
|
||||
|
|
@ -105,6 +110,10 @@ class UVServiceWorker extends EventEmitter {
|
|||
};
|
||||
|
||||
const responseCtx = new ResponseContext(requestCtx, response, this);
|
||||
const resEvent = new HookEvent(responseCtx, null, null);
|
||||
|
||||
this.emit('beforemod', resEvent);
|
||||
if (resEvent.intercepted) return resEvent.returnValue;
|
||||
|
||||
for (const name of this.headers.csp) {
|
||||
if (responseCtx.headers[name]) delete responseCtx.headers[name];
|
||||
|
|
@ -166,9 +175,7 @@ class UVServiceWorker extends EventEmitter {
|
|||
responseCtx.headers['content-type'] = 'text/event-stream';
|
||||
};
|
||||
|
||||
const resEvent = new HookEvent(responseCtx, null, null);
|
||||
this.emit('response', resEvent);
|
||||
|
||||
if (resEvent.intercepted) return resEvent.returnValue;
|
||||
|
||||
return new Response(responseCtx.body, {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue