From cc72f9146558723936276d354eb37b2c281381ef Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 9 Feb 2020 12:47:50 +0900 Subject: [PATCH] Fix cannot update (#5890) --- src/client/sw.js | 4 ++-- src/server/web/index.ts | 4 ++++ src/server/web/views/flash.pug | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/server/web/views/flash.pug diff --git a/src/client/sw.js b/src/client/sw.js index 0ad9e22f1..68e43429a 100644 --- a/src/client/sw.js +++ b/src/client/sw.js @@ -18,7 +18,7 @@ self.addEventListener('install', ev => { caches.open(cacheName) .then(cache => { return cache.addAll([ - '/' + `/?v=${version}` ]); }) .then(() => self.skipWaiting()) @@ -45,7 +45,7 @@ self.addEventListener('fetch', ev => { return response || fetch(ev.request); }) .catch(() => { - return caches.match('/'); + return caches.match(`/?v=${version}`); }) ); }); diff --git a/src/server/web/index.ts b/src/server/web/index.ts index 7f2ecde91..fb3f05611 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -327,6 +327,10 @@ const override = (source: string, target: string, depth: number = 0) => router.get('/othello', async ctx => ctx.redirect(override(ctx.URL.pathname, 'games/reversi', 1))); router.get('/reversi', async ctx => ctx.redirect(override(ctx.URL.pathname, 'games'))); +router.get('/flash', async ctx => { + await ctx.render('flash'); +}); + // Render base html for all requests router.get('*', async ctx => { const meta = await fetchMeta(); diff --git a/src/server/web/views/flash.pug b/src/server/web/views/flash.pug new file mode 100644 index 000000000..f279c2360 --- /dev/null +++ b/src/server/web/views/flash.pug @@ -0,0 +1,20 @@ +doctype html + +html + script. + localStorage.removeItem('locale'); + + try { + navigator.serviceWorker.controller.postMessage('clear'); + + navigator.serviceWorker.getRegistrations().then(registrations => { + return Promise.all(registrations.map(registration => registration.unregister())); + }).then(() => { + location = '/'; + }); + } catch (e) { + console.error(e); + setTimeout(() => { + location = '/'; + }, 10000) + }