mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-22 08:20:10 +00:00
chore(sw): only proxies HTML requests (#9070)
* chore(sw): only proxies HTML requests もはやHTMLじゃなさそうなリクエストにはSWで関与しないようにする こうするといろいろな面倒事が解決するはず…たぶん Resolve #9037 Resolve #9038 * align code style * Update packages/sw/src/sw.ts Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> Co-authored-by: tamaina <tamaina@hotmail.co.jp> Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
parent
d4b146e77a
commit
e60a6cc621
1 changed files with 10 additions and 0 deletions
|
@ -24,6 +24,16 @@ self.addEventListener('activate', ev => {
|
|||
});
|
||||
|
||||
self.addEventListener('fetch', ev => {
|
||||
let isHTMLRequest = false;
|
||||
if (ev.request.headers.get('sec-fetch-dest') === 'document') {
|
||||
isHTMLRequest = true;
|
||||
} else if (ev.request.headers.get('accept')?.includes('/html')) {
|
||||
isHTMLRequest = true;
|
||||
} else if (ev.request.url.endsWith('/')) {
|
||||
isHTMLRequest = true;
|
||||
}
|
||||
|
||||
if (!isHTMLRequest) return;
|
||||
ev.respondWith(
|
||||
fetch(ev.request)
|
||||
.catch(() => new Response(`Offline. Service Worker @${_VERSION_}`, { status: 200 }))
|
||||
|
|
Loading…
Reference in a new issue