This commit is contained in:
Jason 2022-02-23 23:37:37 -05:00
parent 64a7599336
commit fd8064a6d9
14 changed files with 5 additions and 1531 deletions

View file

@ -75,17 +75,19 @@ addEventListener('install', () => {
});
function UVServiceWorker(bare = '/bare/', options) {
function UVServiceWorker(_bare = '/bare/', options) {
try {
return async function handler(event) {
const { request } = event;
const bare = new URL(_bare, location.href);
try {
if (!request.url.startsWith(location.origin + (options.prefix || '/service/'))) {
return fetch(request);
};
const requestCtx = {
url: bare + 'v1/',
url: bare.href + 'v1/',
referrer: false,
headers: {},
forward: headers.forward,
@ -149,7 +151,7 @@ function UVServiceWorker(bare = '/bare/', options) {
headers: !requestCtx.blob ? bareHeaders : requestCtx.headers,
redirect: requestCtx.redirect,
credentials: requestCtx.credentials,
mode: requestCtx.mode,
mode: location.origin !== bare.origin ? 'cors' : requestCtx.mode,
};
if (requestCtx.body) fetchOptions.body = requestCtx.body;