mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-25 08:54:10 +00:00
feature(cloudcmd) add service worker
This commit is contained in:
parent
58c10e201a
commit
234f7bcac0
6 changed files with 164 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue