mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
refactor(sw) move out url checks from fetch
This commit is contained in:
parent
3778c80fd6
commit
98be918c0f
1 changed files with 14 additions and 14 deletions
|
|
@ -8,13 +8,25 @@ const isDev = process.env.NODE_ENV === 'development';
|
|||
|
||||
const wait = currify((f, e) => e.waitUntil(f()));
|
||||
const respondWith = currify((f, e) => {
|
||||
const {url} = e.requestl;
|
||||
const {request} = e;
|
||||
const {url} = request;
|
||||
const pathname = getPathName(url);
|
||||
|
||||
if (/\/$/.test(url) || /\^\/fs/.test(url))
|
||||
if (/\/$/.test(url) || /\^\/fs/.test(pathname))
|
||||
return;
|
||||
|
||||
if (!isGet(request))
|
||||
return;
|
||||
|
||||
if (/^\/api/.test(pathname))
|
||||
return;
|
||||
|
||||
if (/^socket.io/.test(pathname))
|
||||
return;
|
||||
|
||||
e.respondWith(f(e));
|
||||
});
|
||||
|
||||
const getPathName = (url) => new URL(url).pathname;
|
||||
|
||||
const date = codegen`module.exports = '"' + Date() + '"'`;
|
||||
|
|
@ -82,18 +94,6 @@ async function onFetch(event) {
|
|||
if (e)
|
||||
return new Response(e.message);
|
||||
|
||||
if (!isGet(request) || !resp.ok || !isBasic(resp))
|
||||
return resp;
|
||||
|
||||
if (/\/$/.test(pathname))
|
||||
return resp;
|
||||
|
||||
if (/^\/api/.test(pathname))
|
||||
return resp;
|
||||
|
||||
if (/^socket.io/.test(pathname))
|
||||
return resp;
|
||||
|
||||
await addToCache(request, resp.clone());
|
||||
|
||||
return resp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue