mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
fix fetch proxy behavior
This commit is contained in:
parent
bcbb660cc6
commit
ab226abb42
4 changed files with 18 additions and 12 deletions
|
@ -1,3 +1,5 @@
|
|||
import BareClient from "@mercuryworkshop/bare-mux";
|
||||
|
||||
import "./scope.ts";
|
||||
import "./window.ts";
|
||||
import "./event.ts";
|
||||
|
@ -20,5 +22,10 @@ declare global {
|
|||
interface Window {
|
||||
$s: any;
|
||||
$sImport: any;
|
||||
$client: BareClient;
|
||||
}
|
||||
}
|
||||
|
||||
const client = new BareClient();
|
||||
|
||||
export { client };
|
|
@ -1,13 +1,19 @@
|
|||
// ts throws an error if you dont do window.fetch
|
||||
|
||||
import { encodeUrl, rewriteHeaders } from "../shared";
|
||||
import { client } from "../index";
|
||||
|
||||
window.fetch = new Proxy(window.fetch, {
|
||||
apply(target, thisArg, argArray) {
|
||||
argArray[0] = encodeUrl(argArray[0]);
|
||||
async apply(target, thisArg, argArray) {
|
||||
// @ts-expect-error
|
||||
const response = await client.fetch(...argArray);
|
||||
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
return new Response(response.body, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: response.headers
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Headers = new Proxy(Headers, {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { decodeUrl } from "../../shared/rewriters/url";
|
||||
import { BareClient } from "../shared";
|
||||
const client = new BareClient();
|
||||
import { client } from "../index";
|
||||
|
||||
WebSocket = new Proxy(WebSocket, {
|
||||
construct(target, args) {
|
||||
|
|
|
@ -15,12 +15,6 @@ export const windowProxy = new Proxy(window, {
|
|||
return window.parent;
|
||||
} else if (propIsString && prop === "$scramjet") {
|
||||
return;
|
||||
} else if (propIsString && prop === "addEventListener") {
|
||||
return new Proxy(window.addEventListener, {
|
||||
apply(target1, thisArg, argArray) {
|
||||
window.addEventListener(argArray[0], argArray[1]);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const value = Reflect.get(target, prop);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue