@micro-lc/preview 0.5.0-rc3 → 0.5.0-rc4
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -95,5 +95,11 @@ self.addEventListener("fetch", (event) => {
|
|
95
95
|
} catch (e) {
|
96
96
|
finalUrl = url;
|
97
97
|
}
|
98
|
-
|
98
|
+
console.log({ clientId, clientSourceMap, finalUrl });
|
99
|
+
event.respondWith(
|
100
|
+
self.fetch(finalUrl, { ...event.request, headers }).catch((error) => {
|
101
|
+
console.error(error);
|
102
|
+
return Promise.reject(error);
|
103
|
+
})
|
104
|
+
);
|
99
105
|
});
|
@@ -1 +1 @@
|
|
1
|
-
const k=new Map,S=new Map,
|
1
|
+
const k=new Map,S=new Map,w=new Map,y=(e,r)=>{const t=r.keys();let i,{done:s=!1,value:a}=t.next();for(;!s&&i===void 0;){a!==void 0&&e.startsWith(a)&&(i=a,s=!0);const{value:d,done:n=!1}=t.next();s=n,a=d}return i},v=(e,r)=>{self.clients.get(e).then(t=>t==null?void 0:t.postMessage(r)).catch(t=>console.error(`[SW]: error on ${e} - ${String(t)}`))},x=e=>e!==null&&"id"in e;self.addEventListener("install",()=>{self.skipWaiting().catch(e=>console.error(`[SW] error while skipWaiting - ${String(e)}`))});self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())});self.addEventListener("message",({data:e,source:r})=>{if(!x(r))return;const{id:t}=r,i=e;switch(i.type){case"set-source-map":{const{content:{scope:s,dictionary:a}}=i,d=s??t,n=Object.entries(a).reduce((u,[l,c])=>{const{clientSourceMap:g,clientTosMap:p}=u;return Object.keys(c.headers).length>0&&p.set(c.to,c.headers),g.set(l,c),u},{clientSourceMap:new Map,clientTosMap:new Map});s?w.set(t,s):w.delete(t),k.set(d,n.clientSourceMap),S.set(d,n.clientTosMap),v(t,{content:{clientId:t},type:"source-map-ack"});break}case"unload-client":{w.delete(t);break}}});self.addEventListener("fetch",e=>{var r,t,i;const s=e.clientId!==""?e.clientId:e.resultingClientId,a=w.get(s),d=a??s,n=k.get(d);if(!n)return e.respondWith(self.fetch(e.request));const u=S.get(d);let{request:{url:l}}=e;const c=y(l,n),g=y(l,u),p=new Headers(e.request.headers);let b={};if(c!==void 0){const o=(r=n.get(c))==null?void 0:r.to,h=(t=n.get(c))==null?void 0:t.headers,f=l.substring(c.length);b=(i=n.get(c))==null?void 0:i.query,l=`${o}${f}`,Object.entries(h).forEach(([I,W])=>p.set(I,W))}if(g!==void 0){const o=u.get(g);Object.entries(o).forEach(([h,f])=>p.set(h,f))}let M;try{const o=new URL(l);Object.entries(b).forEach(([h,f])=>o.searchParams.set(h,f)),M=o.href}catch{M=l}console.log({clientId:s,clientSourceMap:n,finalUrl:M}),e.respondWith(self.fetch(M,{...e.request,headers:p}).catch(o=>(console.error(o),Promise.reject(o))))});
|