Refactoring about how proxy fetching happens
This commit is contained in:
+1
-1
@@ -394,7 +394,7 @@ export class Client {
|
||||
|
||||
settings = expandPropertyNames(settings);
|
||||
|
||||
console.log("Settings", settings);
|
||||
// console.log("Settings", settings);
|
||||
|
||||
if (!settings.indexPage) {
|
||||
settings.indexPage = "[[index]]";
|
||||
|
||||
+25
-14
@@ -5,6 +5,10 @@ import {
|
||||
ProxyFetchResponse,
|
||||
} from "../../common/proxy_fetch.ts";
|
||||
import type { Client } from "../client.ts";
|
||||
import {
|
||||
base64Decode,
|
||||
base64Encode,
|
||||
} from "../../plugos/asset_bundle/base64.ts";
|
||||
|
||||
export function sandboxFetchSyscalls(
|
||||
client: Client,
|
||||
@@ -13,25 +17,32 @@ export function sandboxFetchSyscalls(
|
||||
"sandboxFetch.fetch": async (
|
||||
_ctx,
|
||||
url: string,
|
||||
options: ProxyFetchRequest,
|
||||
options?: ProxyFetchRequest,
|
||||
): Promise<ProxyFetchResponse> => {
|
||||
// console.log("Got sandbox fetch ", url);
|
||||
// console.log("Got sandbox fetch ", url, op);
|
||||
url = url.replace(/^https?:\/\//, "");
|
||||
const fetchOptions = options
|
||||
? {
|
||||
method: options.method,
|
||||
headers: options.headers,
|
||||
body: options.base64Body && base64Decode(options.base64Body),
|
||||
}
|
||||
: {};
|
||||
if (!client.remoteSpacePrimitives) {
|
||||
// No SB server to proxy the fetch available so let's execute the request directly
|
||||
return performLocalFetch(url, options);
|
||||
return performLocalFetch(url, fetchOptions);
|
||||
}
|
||||
const resp = client.remoteSpacePrimitives.authenticatedFetch(
|
||||
`${client.remoteSpacePrimitives.url}/.rpc`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
operation: "fetch",
|
||||
url,
|
||||
options,
|
||||
}),
|
||||
},
|
||||
const resp = await client.remoteSpacePrimitives.authenticatedFetch(
|
||||
`${client.remoteSpacePrimitives.url}/!${url}`,
|
||||
fetchOptions,
|
||||
);
|
||||
return (await resp).json();
|
||||
const body = await resp.arrayBuffer();
|
||||
return {
|
||||
ok: resp.ok,
|
||||
status: resp.status,
|
||||
headers: Object.fromEntries(resp.headers.entries()),
|
||||
base64Body: base64Encode(new Uint8Array(body)),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,10 @@ export function yamlSyscalls(): SysCallMapping {
|
||||
return YAML.parse(text);
|
||||
},
|
||||
"yaml.stringify": (_ctx, obj: any): string => {
|
||||
return YAML.stringify(obj);
|
||||
return YAML.stringify(obj, {
|
||||
noArrayIndent: true,
|
||||
noCompatMode: true,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user