about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2018-05-16 11:59:44 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-16 04:59:44 +0200
commit65d6b253fb4d8a81d41ecfa25078205569fcef21 (patch)
tree5d326051cea8a288235aad7c229b9ff3a1637858
parent17c1a62ec81e78f45c44882a5aba19ef8e7aeb44 (diff)
Let navigator follow redirect instead that handling redirect in fetch (#7500)
* Let navigator follow redirect instead that handling redirect in fetch

* Do not use cache when fetched resource is to redirect
-rw-r--r--app/javascript/mastodon/service_worker/entry.js14
1 files changed, 5 insertions, 9 deletions
diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js
index 89414f100..5955e9146 100644
--- a/app/javascript/mastodon/service_worker/entry.js
+++ b/app/javascript/mastodon/service_worker/entry.js
@@ -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();