Skip to content

Instantly share code, notes, and snippets.

@tkdaj
Last active May 3, 2022 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkdaj/9aa196792ba8aac3279ef9e9af3f54ba to your computer and use it in GitHub Desktop.
Save tkdaj/9aa196792ba8aac3279ef9e9af3f54ba to your computer and use it in GitHub Desktop.
self.addEventListener('fetch', e => {
if(someValue) {
e.respondWith((async () => {
const res = await fetch('my/api');
asyncDecision = await res.text();
return asyncDecision === 'true' ? await fetch('path1') : await fetch(e.request);
})());
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment