diff --git a/.prettierignore b/.prettierignore index 64914fb..7fdbbf1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,4 +2,5 @@ pnpm-lock.yaml README.md tsconfig.json tests/ -dist/ \ No newline at end of file +dist/ +rewriter/ diff --git a/.prettierrc.js b/.prettierrc.js index 874c2df..b8b614a 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -2,7 +2,7 @@ * @type {import("prettier").Config} */ const config = { - trailingComma: "es6", + trailingComma: "es5", useTabs: true, semi: true, singleQuote: false, diff --git a/server.js b/server.js index 8cfe2e5..1f41dc2 100644 --- a/server.js +++ b/server.js @@ -68,7 +68,7 @@ fastify.register(fastifyStatic, { }); fastify.listen({ port: process.env.PORT || 1337, - host: "0.0.0.0" + host: "0.0.0.0", }); const watch = spawn("pnpm", ["rspack", "-w"], { diff --git a/src/client/import.ts b/src/client/import.ts index 631a67b..fafe095 100644 --- a/src/client/import.ts +++ b/src/client/import.ts @@ -1,8 +1,10 @@ -import { encodeUrl } from "../shared/rewriters/url"; +import { encodeUrl } from "../shared/rewriters/url"; -window.$sImport = function(base) { - return function(url) { - let resolved = new URL(url, base).href - return (function() { }.constructor(`return import("${encodeUrl(resolved)}")`))(); - } -} +window.$sImport = function (base) { + return function (url) { + let resolved = new URL(url, base).href; + return function () {}.constructor( + `return import("${encodeUrl(resolved)}")` + )(); + }; +}; diff --git a/src/shared/rewriters/js.ts b/src/shared/rewriters/js.ts index 8934b29..8e6b868 100644 --- a/src/shared/rewriters/js.ts +++ b/src/shared/rewriters/js.ts @@ -1,7 +1,11 @@ import { decodeUrl } from "./url"; // i am a cat. i like to be petted. i like to be fed. i like to be -import { initSync, rewrite_js, rewrite_js_from_arraybuffer } from "../../../rewriter/out/rewriter.js"; +import { + initSync, + rewrite_js, + rewrite_js_from_arraybuffer, +} from "../../../rewriter/out/rewriter.js"; import "../../../static/wasm.js"; initSync( @@ -12,8 +16,7 @@ initSync( global.rws = rewriteJs; export function rewriteJs(js: string | ArrayBuffer, origin?: URL) { - if ("window" in globalThis) - origin ??= new URL(decodeUrl(location.href)); + if ("window" in globalThis) origin ??= new URL(decodeUrl(location.href)); const before = performance.now(); if (typeof js === "string") { diff --git a/src/worker/fetch.ts b/src/worker/fetch.ts index c6af2a6..3febbc2 100644 --- a/src/worker/fetch.ts +++ b/src/worker/fetch.ts @@ -15,7 +15,6 @@ export async function swfetch( ) { const urlParam = new URLSearchParams(new URL(request.url).search); - if (urlParam.has("url")) { return Response.redirect( encodeUrl(urlParam.get("url"), new URL(urlParam.get("url"))) @@ -37,7 +36,6 @@ export async function swfetch( duplex: "half", }); - return await handleResponse(url, request.destination, response); } catch (err) { console.error("ERROR FROM SERVICE WORKER FETCH", err); @@ -48,13 +46,15 @@ export async function swfetch( } } - -async function handleResponse(url: URL, destination: RequestDestination, response: BareResponseFetch): Promise { +async function handleResponse( + url: URL, + destination: RequestDestination, + response: BareResponseFetch +): Promise { let responseBody: string | ArrayBuffer | ReadableStream; const responseHeaders = rewriteHeaders(response.rawHeaders, url); - - await handleCookies(url, (responseHeaders["set-cookie"] || []) as string[]) + await handleCookies(url, (responseHeaders["set-cookie"] || []) as string[]); for (const header in responseHeaders) { // flatten everything past here @@ -124,7 +124,6 @@ async function handleResponse(url: URL, destination: RequestDestination, respons }); } - async function handleCookies(url: URL, headers: string[]) { const cookieStore = new IDBMap(url.host, { durability: "relaxed", @@ -142,8 +141,7 @@ async function handleCookies(url: URL, headers: string[]) { cookieParsed = cookieParsed.filter((x) => x[0] !== "Domain"); let host = hostArg ? hostArg[1] : undefined; - if (url.protocol === "http" && cookieParsed.includes(["Secure"])) - continue; + if (url.protocol === "http" && cookieParsed.includes(["Secure"])) continue; if ( cookieParsed.includes(["SameSite", "None"]) && !cookieParsed.includes(["Secure"])