]> cat aescling's git repositories - mastodon.git/commitdiff
Let navigator follow redirect instead that handling redirect in fetch (#7500)
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
Wed, 16 May 2018 02:59:44 +0000 (11:59 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 16 May 2018 02:59:44 +0000 (04:59 +0200)
* Let navigator follow redirect instead that handling redirect in fetch

* Do not use cache when fetched resource is to redirect

app/javascript/mastodon/service_worker/entry.js

index 89414f1006f8f6d93534ac27fd75a5ee4e110693..5955e914699df2ffc70cca44844c0acb07045ce1 100644 (file)
@@ -10,7 +10,7 @@ function openWebCache() {
 }
 
 function fetchRoot() {
-  return fetch('/', { credentials: 'include' });
+  return fetch('/', { credentials: 'include', redirect: 'manual' });
 }
 
 const firefox = navigator.userAgent.match(/Firefox\/(\d+)/);
@@ -31,14 +31,10 @@ self.addEventListener('fetch', function(event) {
     const asyncResponse = fetchRoot();
     const asyncCache = openWebCache();
 
-    event.respondWith(asyncResponse.then(response => {
-      if (response.ok) {
-        return asyncCache.then(cache => cache.put('/', response.clone()))
-                         .then(() => response);
-      }
-
-      throw null;
-    }).catch(() => asyncCache.then(cache => cache.match('/'))));
+    event.respondWith(asyncResponse.then(
+      response => asyncCache.then(cache => cache.put('/', response.clone()))
+                            .then(() => response),
+      () => asyncCache.then(cache => cache.match('/'))));
   } else if (url.pathname === '/auth/sign_out') {
     const asyncResponse = fetch(event.request);
     const asyncCache = openWebCache();