This commit is contained in:
Rizky 2024-04-17 19:05:24 +07:00
parent e20ea7abaf
commit 6077684a91
1 changed files with 10 additions and 3 deletions

View File

@ -1,13 +1,14 @@
import { apiContext } from "service-srv"; import { apiContext } from "service-srv";
export const _ = { export const _ = {
url: "/_proxy/*", url: "/_proxy/**",
raw: true, raw: true,
async api() { async api() {
const { req } = apiContext(this); const { req } = apiContext(this);
try { try {
const url = new URL(decodeURIComponent(req.params["_"])); const raw_url = decodeURIComponent(req.params["_"]);
const url = new URL(raw_url) as URL;
const body = await req.arrayBuffer(); const body = await req.arrayBuffer();
const headers = {} as Record<string, string>; const headers = {} as Record<string, string>;
req.headers.forEach((v, k) => { req.headers.forEach((v, k) => {
@ -18,11 +19,17 @@ export const _ = {
headers[k] = v; headers[k] = v;
}); });
return await fetch(url, { const res = await fetch(url, {
method: req.method || "POST", method: req.method || "POST",
headers, headers,
body, body,
}); });
if (res.headers.get("content-encoding")) {
res.headers.delete("content-encoding");
}
return res;
} catch (e: any) { } catch (e: any) {
console.error(e); console.error(e);
new Response( new Response(