chore: prettier

This commit is contained in:
velzie 2024-07-17 20:16:02 -04:00
parent bd08461dbe
commit 4f3fe2813e
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
6 changed files with 26 additions and 22 deletions

View file

@ -2,4 +2,5 @@ pnpm-lock.yaml
README.md
tsconfig.json
tests/
dist/
dist/
rewriter/

View file

@ -2,7 +2,7 @@
* @type {import("prettier").Config}
*/
const config = {
trailingComma: "es6",
trailingComma: "es5",
useTabs: true,
semi: true,
singleQuote: false,

View file

@ -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"], {

View file

@ -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)}")`
)();
};
};

View file

@ -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") {

View file

@ -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<Response> {
async function handleResponse(
url: URL,
destination: RequestDestination,
response: BareResponseFetch
): Promise<Response> {
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"])