mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
chore: prettier
This commit is contained in:
parent
bd08461dbe
commit
4f3fe2813e
6 changed files with 26 additions and 22 deletions
|
@ -3,3 +3,4 @@ README.md
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
tests/
|
tests/
|
||||||
dist/
|
dist/
|
||||||
|
rewriter/
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @type {import("prettier").Config}
|
* @type {import("prettier").Config}
|
||||||
*/
|
*/
|
||||||
const config = {
|
const config = {
|
||||||
trailingComma: "es6",
|
trailingComma: "es5",
|
||||||
useTabs: true,
|
useTabs: true,
|
||||||
semi: true,
|
semi: true,
|
||||||
singleQuote: false,
|
singleQuote: false,
|
||||||
|
|
|
@ -68,7 +68,7 @@ fastify.register(fastifyStatic, {
|
||||||
});
|
});
|
||||||
fastify.listen({
|
fastify.listen({
|
||||||
port: process.env.PORT || 1337,
|
port: process.env.PORT || 1337,
|
||||||
host: "0.0.0.0"
|
host: "0.0.0.0",
|
||||||
});
|
});
|
||||||
|
|
||||||
const watch = spawn("pnpm", ["rspack", "-w"], {
|
const watch = spawn("pnpm", ["rspack", "-w"], {
|
||||||
|
|
|
@ -2,7 +2,9 @@ import { encodeUrl } from "../shared/rewriters/url";
|
||||||
|
|
||||||
window.$sImport = function (base) {
|
window.$sImport = function (base) {
|
||||||
return function (url) {
|
return function (url) {
|
||||||
let resolved = new URL(url, base).href
|
let resolved = new URL(url, base).href;
|
||||||
return (function() { }.constructor(`return import("${encodeUrl(resolved)}")`))();
|
return function () {}.constructor(
|
||||||
}
|
`return import("${encodeUrl(resolved)}")`
|
||||||
}
|
)();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
import { decodeUrl } from "./url";
|
import { decodeUrl } from "./url";
|
||||||
|
|
||||||
// i am a cat. i like to be petted. i like to be fed. i like to be
|
// 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";
|
import "../../../static/wasm.js";
|
||||||
|
|
||||||
initSync(
|
initSync(
|
||||||
|
@ -12,8 +16,7 @@ initSync(
|
||||||
|
|
||||||
global.rws = rewriteJs;
|
global.rws = rewriteJs;
|
||||||
export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {
|
export function rewriteJs(js: string | ArrayBuffer, origin?: URL) {
|
||||||
if ("window" in globalThis)
|
if ("window" in globalThis) origin ??= new URL(decodeUrl(location.href));
|
||||||
origin ??= new URL(decodeUrl(location.href));
|
|
||||||
|
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
if (typeof js === "string") {
|
if (typeof js === "string") {
|
||||||
|
|
|
@ -15,7 +15,6 @@ export async function swfetch(
|
||||||
) {
|
) {
|
||||||
const urlParam = new URLSearchParams(new URL(request.url).search);
|
const urlParam = new URLSearchParams(new URL(request.url).search);
|
||||||
|
|
||||||
|
|
||||||
if (urlParam.has("url")) {
|
if (urlParam.has("url")) {
|
||||||
return Response.redirect(
|
return Response.redirect(
|
||||||
encodeUrl(urlParam.get("url"), new URL(urlParam.get("url")))
|
encodeUrl(urlParam.get("url"), new URL(urlParam.get("url")))
|
||||||
|
@ -37,7 +36,6 @@ export async function swfetch(
|
||||||
duplex: "half",
|
duplex: "half",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return await handleResponse(url, request.destination, response);
|
return await handleResponse(url, request.destination, response);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("ERROR FROM SERVICE WORKER FETCH", err);
|
console.error("ERROR FROM SERVICE WORKER FETCH", err);
|
||||||
|
@ -48,13 +46,15 @@ export async function swfetch(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleResponse(
|
||||||
async function handleResponse(url: URL, destination: RequestDestination, response: BareResponseFetch): Promise<Response> {
|
url: URL,
|
||||||
|
destination: RequestDestination,
|
||||||
|
response: BareResponseFetch
|
||||||
|
): Promise<Response> {
|
||||||
let responseBody: string | ArrayBuffer | ReadableStream;
|
let responseBody: string | ArrayBuffer | ReadableStream;
|
||||||
const responseHeaders = rewriteHeaders(response.rawHeaders, url);
|
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) {
|
for (const header in responseHeaders) {
|
||||||
// flatten everything past here
|
// flatten everything past here
|
||||||
|
@ -124,7 +124,6 @@ async function handleResponse(url: URL, destination: RequestDestination, respons
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleCookies(url: URL, headers: string[]) {
|
async function handleCookies(url: URL, headers: string[]) {
|
||||||
const cookieStore = new IDBMap(url.host, {
|
const cookieStore = new IDBMap(url.host, {
|
||||||
durability: "relaxed",
|
durability: "relaxed",
|
||||||
|
@ -142,8 +141,7 @@ async function handleCookies(url: URL, headers: string[]) {
|
||||||
cookieParsed = cookieParsed.filter((x) => x[0] !== "Domain");
|
cookieParsed = cookieParsed.filter((x) => x[0] !== "Domain");
|
||||||
let host = hostArg ? hostArg[1] : undefined;
|
let host = hostArg ? hostArg[1] : undefined;
|
||||||
|
|
||||||
if (url.protocol === "http" && cookieParsed.includes(["Secure"]))
|
if (url.protocol === "http" && cookieParsed.includes(["Secure"])) continue;
|
||||||
continue;
|
|
||||||
if (
|
if (
|
||||||
cookieParsed.includes(["SameSite", "None"]) &&
|
cookieParsed.includes(["SameSite", "None"]) &&
|
||||||
!cookieParsed.includes(["Secure"])
|
!cookieParsed.includes(["Secure"])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue