mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 23:30:28 +03:00
Revise our fetch to be more in line with W3C spec
This commit is contained in:
parent
f100279e65
commit
07e15e2421
1 changed files with 10 additions and 2 deletions
12
src/sw.ts
12
src/sw.ts
|
|
@ -76,13 +76,21 @@ self.addEventListener('fetch', (event: FetchEvent) => {
|
||||||
}
|
}
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
(async (): Promise<Response> => {
|
(async (): Promise<Response> => {
|
||||||
console.log('Unironic race condition mitigation it seems.');
|
if (!event.clientId) throw new Error('Missing clientId');
|
||||||
const client = await self.clients.get(event.clientId);
|
const client = await self.clients.get(event.clientId);
|
||||||
const token: string = await sendAndWaitForReply(client, 'token', {});
|
if (!client) throw new Error('Client not found');
|
||||||
|
const token = await sendAndWaitForReply(client, 'token', {});
|
||||||
|
if (!token) throw new Error('Failed to retrieve token');
|
||||||
const response = await fetch(url, fetchConfig(token));
|
const response = await fetch(url, fetchConfig(token));
|
||||||
|
if (!response.ok) throw new Error(`Fetch failed: ${response.statusText}`);
|
||||||
return response;
|
return response;
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
|
event.waitUntil(
|
||||||
|
(async function () {
|
||||||
|
console.log('Ensuring fetch processing completes before worker termination.');
|
||||||
|
})()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const onPushNotification = async (event: PushEvent) => {
|
const onPushNotification = async (event: PushEvent) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue