Minor bug fix in service worker
parent
481387d235
commit
5904326f0c
|
@ -1,4 +1,4 @@
|
||||||
import { base64Decode, base64Encode } from "../lib/crypto.ts";
|
import { base64Decode, base64Encode } from "$lib/crypto.ts";
|
||||||
|
|
||||||
export type ProxyFetchRequest = {
|
export type ProxyFetchRequest = {
|
||||||
method?: string;
|
method?: string;
|
||||||
|
|
|
@ -71,8 +71,12 @@ self.addEventListener("fetch", (event: any) => {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
(async () => {
|
(async () => {
|
||||||
const request = event.request;
|
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
|
// 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")) {
|
if (request.headers.has("x-sync-mode")) {
|
||||||
|
@ -91,14 +95,8 @@ self.addEventListener("fetch", (event: any) => {
|
||||||
return fetch(request);
|
return fetch(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestUrl = new URL(request.url);
|
|
||||||
const pathname = requestUrl.pathname;
|
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") {
|
if (pathname === "/.auth" || pathname === "/index.json") {
|
||||||
return fetch(request);
|
return fetch(request);
|
||||||
} else if (/\/.+\.[a-zA-Z]+$/.test(pathname)) {
|
} else if (/\/.+\.[a-zA-Z]+$/.test(pathname)) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import type { SysCallMapping } from "../../lib/plugos/system.ts";
|
import type { SysCallMapping } from "$lib/plugos/system.ts";
|
||||||
import {
|
import {
|
||||||
performLocalFetch,
|
performLocalFetch,
|
||||||
ProxyFetchRequest,
|
ProxyFetchRequest,
|
||||||
ProxyFetchResponse,
|
ProxyFetchResponse,
|
||||||
} from "$common/proxy_fetch.ts";
|
} from "$common/proxy_fetch.ts";
|
||||||
import type { Client } from "../client.ts";
|
import type { Client } from "../client.ts";
|
||||||
import { base64Decode, base64Encode } from "../../lib/crypto.ts";
|
import { base64Decode, base64Encode } from "$lib/crypto.ts";
|
||||||
|
|
||||||
export function sandboxFetchSyscalls(
|
export function sandboxFetchSyscalls(
|
||||||
client: Client,
|
client: Client,
|
||||||
|
|
Loading…
Reference in New Issue