From da3f21cad235a133f4f44b88c86716bc770e99aa Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 22 Jan 2024 11:38:36 +0700 Subject: [PATCH] wip fix proxy --- app/web/src/base/load/api/api-proxy-def.tsx | 2 +- app/web/src/base/load/api/api-proxy.tsx | 2 +- pkgs/core/api/_prasi.ts | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/web/src/base/load/api/api-proxy-def.tsx b/app/web/src/base/load/api/api-proxy-def.tsx index 4753742c..1a6c92bd 100644 --- a/app/web/src/base/load/api/api-proxy-def.tsx +++ b/app/web/src/base/load/api/api-proxy-def.tsx @@ -29,7 +29,7 @@ export const loadApiProxyDef = async (url: string, with_types: boolean) => { apiEntry: (await apiEntry.json()).srv, }; - if (with_types) { + if (with_types) { const apiTypes = await fetch(base + "/_prasi/api-types"); w.prasiApi[url].apiTypes = await apiTypes.text(); w.prasiApi[url].prismaTypes = { diff --git a/app/web/src/base/load/api/api-proxy.tsx b/app/web/src/base/load/api/api-proxy.tsx index 90e2bfe9..a43cb776 100644 --- a/app/web/src/base/load/api/api-proxy.tsx +++ b/app/web/src/base/load/api/api-proxy.tsx @@ -13,7 +13,7 @@ export const apiProxy = (api_url: string) => { try { const base = new URL(api_url); - const base_url = `${base.protocol}//${base.host}`; + let base_url = `${base.protocol}//${base.host}`; if (!w.prasiApi[base_url]) { if (!apiProxyLoaded[base_url]) { apiProxyLoaded[base_url] = loadApiProxyDef(base_url, true); diff --git a/pkgs/core/api/_prasi.ts b/pkgs/core/api/_prasi.ts index 3ab6b806..06a2cb29 100644 --- a/pkgs/core/api/_prasi.ts +++ b/pkgs/core/api/_prasi.ts @@ -32,9 +32,8 @@ export const _ = { if (mode === "dev") { src = `\ (() => { - const baseurl = new URL("https://prasi.avolut.com/"); - baseurl.pathname = ''; - const url = baseurl.toString(); + //[[REPLACE]] + const url = \`\${baseurl.protocol}//\${baseurl.host}\`; const w = window; if (!w.prasiApi) { w.prasiApi = {}; @@ -52,9 +51,8 @@ export const _ = { } else { src = `\ (() => { - const baseurl = new URL("https://prasi.avolut.com/"); - baseurl.pathname = ''; - const url = baseurl.toString(); + //[[REPLACE]] + const url = \`\${baseurl.protocol}//\${baseurl.host}\`; const w = window; if (!w.prasiApi) { w.prasiApi = {}; @@ -65,7 +63,10 @@ export const _ = { })();`; } - cache[mode] = src; + cache[mode] = src.replace( + "//[[REPLACE]]", + `const baseurl = new URL(${url})` + ); } res.send(cache[mode]);