wip fix server pathname

This commit is contained in:
Rizky 2024-02-11 09:35:02 +07:00
parent 1514dffd4c
commit bf1a6bd3a2
7 changed files with 48 additions and 30 deletions

View File

@ -120,7 +120,7 @@ declare global {
type PrasiServer = {
ws?: WebSocketHandler<{ url: string }>;
http: (arg: {
url: URL;
url: { raw: URL; pathname: string };
req: Request;
server: Server;
mode: "dev" | "prod";

View File

@ -86,8 +86,14 @@ const serverMain = () => ({
return new Response("Upgrade failed :(", { status: 500 });
}
const pathname = `/${arg.url.pathname.split("/").slice(3).join("/")}`;
return await handler.http({
...arg,
url: {
pathname,
raw: arg.url,
},
mode: "dev",
index: prodIndex(site_id),
});
@ -104,7 +110,7 @@ const serverMain = () => ({
type PrasiServer = {
ws?: WebSocketHandler<{ url: string }>;
http: (arg: {
url: URL;
url: { raw: URL; pathname: string };
req: Request;
server: Server;
handle: (req: Request) => Promise<undefined | Response>;

View File

@ -52,7 +52,6 @@ export const apiProxy = (api_url: string) => {
);
return;
}
}
let actionUrl = api_ref.apiEntry[actionName].url;
const actionParams = api_ref.apiEntry[actionName].args;
@ -60,7 +59,10 @@ export const apiProxy = (api_url: string) => {
if (rest.length > 0 && actionParams.length > 0) {
for (const [idx, p] of Object.entries(rest)) {
const paramName = actionParams[parseInt(idx)];
if (actionParams && actionParams.includes(paramName)) {
if (
actionParams &&
actionParams.includes(paramName)
) {
if (
!!p &&
typeof p !== "string" &&
@ -69,8 +71,14 @@ export const apiProxy = (api_url: string) => {
continue;
}
}
actionUrl = actionUrl.replace(`:${paramName}?`, p + "");
actionUrl = actionUrl.replace(`:${paramName}`, p + "");
actionUrl = actionUrl.replace(
`:${paramName}?`,
p + ""
);
actionUrl = actionUrl.replace(
`:${paramName}`,
p + ""
);
}
}
@ -81,6 +89,9 @@ export const apiProxy = (api_url: string) => {
} else {
console.error(`API Not Found: ${actionName.toString()}`);
}
} else {
reject("Failed to load API: " + base_url);
}
} catch (e) {
reject(e);
}

View File

@ -57,7 +57,8 @@ export const EdApiServer = forwardRef<
try {
if (dev) {
const vdev = JSON.parse(localStorage.getItem("prasi-dev") || "{}");
if (vdev) {
if (vdev && Object.keys(vdev).length > 0) {
dev.url = vdev.url;
dev.enabled = vdev.enabled;
}
@ -167,8 +168,10 @@ export const EdApiServer = forwardRef<
local.api_url.startsWith("http://") ||
local.api_url.startsWith("https://")
) {
if (local.api_url.length > 8) {
local.api_url = trim(local.api_url, "/");
}
}
local.render();
}}
onFocus={(e) => {

View File

@ -48,12 +48,14 @@ export const apiUrl = function (p: PG): string {
export const checkAPI = async (p: PG) => {
const url = apiUrl(p);
if (!url) return "offline";
try {
if (!apiRef[url]) apiRef[url] = apiProxy(url) as any;
const capi = apiRef[url];
if (!capi) {
console.error(`Cannot initialize API for ${url}.`, w.prasiApi[url]);
} else {
@ -61,6 +63,7 @@ export const checkAPI = async (p: PG) => {
type: "check",
id_site: p.site.id,
});
if (!res) {
return { deployable: false, db: "", hasDB: false, domains: [] };
} else {

View File

@ -1,5 +0,0 @@
{
"linter": {
"enabled": false
}
}