feature(cloudcmd) add service worker

This commit is contained in:
coderaiser 2018-05-17 16:08:02 +03:00
parent 58c10e201a
commit 234f7bcac0
6 changed files with 164 additions and 2 deletions

View file

@ -39,6 +39,7 @@ const defaultHtml = fs.readFileSync(getIndexPath(isDev), 'utf8');
const auth = currify(_auth);
const setUrl = currify(_setUrl);
const setSW = currify(_setSW);
const root = () => config('root');
@ -208,6 +209,7 @@ function cloudcmd(prefix, plugins, modules) {
}),
setUrl(prefix),
setSW(prefix),
logout,
authentication(),
config.middle,
@ -272,6 +274,22 @@ function _setUrl(pref, req, res, next) {
next();
}
function _setSW(pref, req, res, next) {
const prefix = getPrefix(pref);
const is = !req.url.indexOf(prefix);
if (!is)
return next();
const url = replacePrefix(req.url, prefix);
const isSW = /^\/sw\.js(\.map)?$/.test(url);
if (isSW)
req.url = replaceDist(`/dist${url}`);
next();
}
function checkPlugins(plugins) {
if (typeof plugins === 'undefined')
return;