fix(client) logout: servicer worker: unregister

This commit is contained in:
coderaiser 2018-06-04 14:43:16 +03:00
parent 82807b2c5c
commit 54ce29d33e
3 changed files with 23 additions and 8 deletions

View file

@ -8,7 +8,11 @@ const inherits = require('inherits');
const rendy = require('rendy/legacy');
const exec = require('execon');
const Images = require('./dom/images');
const registerSW = require('./sw/register');
const {
registerSW,
unregisterSW,
} = require('./sw/register');
const join = require('join-io/www/join');
const jonny = require('jonny/legacy');
const currify = require('currify/legacy');
@ -284,7 +288,11 @@ function CloudCmdProto(Util, DOM) {
const url = CloudCmd.PREFIX + '/logout';
const error = () => document.location.reload();
DOM.load.ajax({url, error});
unregisterSW();
DOM.load.ajax({
url,
error,
});
};
function initModules(callback) {

View file

@ -2,7 +2,10 @@
const runtime = require('serviceworker-webpack-plugin/lib/runtime');
module.exports = () => {
module.exports.registerSW = registerSW;
module.exports.unregisterSW = unregisterSW;
async function registerSW() {
if (!navigator.serviceWorker)
return;
@ -12,6 +15,11 @@ module.exports = () => {
if (!isHTTPS && !isLocalhost)
return;
runtime.register();
};
return runtime.register();
}
async function unregisterSW() {
const reg = await registerSW();
return reg.unregister();
}

View file

@ -67,7 +67,7 @@ async function onFetch(event) {
if (!isGet(request) || !resp.ok || !isBasic(resp))
return resp;
if (/^\/$/.test(pathname))
if (/\/$/.test(pathname))
return resp;
if (/^\/api/.test(pathname))
@ -83,7 +83,6 @@ async function onFetch(event) {
async function addToCache(request, response) {
const cache = await caches.open(NAME);
cache.put(request, response);
return cache.put(request, response);
}