Minor bug fix in service worker

pull/753/head
Zef Hemel 2024-02-25 13:46:02 +01:00
parent 481387d235
commit 5904326f0c
3 changed files with 8 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import { base64Decode, base64Encode } from "../lib/crypto.ts";
import { base64Decode, base64Encode } from "$lib/crypto.ts";
export type ProxyFetchRequest = {
method?: string;

View File

@ -71,8 +71,12 @@ self.addEventListener("fetch", (event: any) => {
event.respondWith(
(async () => {
const request = event.request;
const requestUrl = new URL(request.url);
// console.log("Getting request", request, [...request.headers.entries()]);
// Are we fetching a URL from the same origin as the app? If not, we don't handle it and pass it on
if (location.host !== requestUrl.host) {
return fetch(request);
}
// Any request with the X-Sync-Mode header originates from the sync engine: pass it on to the server
if (request.headers.has("x-sync-mode")) {
@ -91,14 +95,8 @@ self.addEventListener("fetch", (event: any) => {
return fetch(request);
}
const requestUrl = new URL(request.url);
const pathname = requestUrl.pathname;
// Are we fetching a URL from the same origin as the app? If not, we don't handle it and pass it on
if (location.host !== requestUrl.host) {
return fetch(request);
}
if (pathname === "/.auth" || pathname === "/index.json") {
return fetch(request);
} else if (/\/.+\.[a-zA-Z]+$/.test(pathname)) {

View File

@ -1,11 +1,11 @@
import type { SysCallMapping } from "../../lib/plugos/system.ts";
import type { SysCallMapping } from "$lib/plugos/system.ts";
import {
performLocalFetch,
ProxyFetchRequest,
ProxyFetchResponse,
} from "$common/proxy_fetch.ts";
import type { Client } from "../client.ts";
import { base64Decode, base64Encode } from "../../lib/crypto.ts";
import { base64Decode, base64Encode } from "$lib/crypto.ts";
export function sandboxFetchSyscalls(
client: Client,