wip fix server pathname
This commit is contained in:
parent
1514dffd4c
commit
bf1a6bd3a2
|
|
@ -8,7 +8,7 @@ glb.ws_hook = {
|
|||
server.ws("ping", ws, data);
|
||||
},
|
||||
pong(ws, data) {
|
||||
server.ws("pong", ws, data);
|
||||
server.ws("pong", ws, data);
|
||||
},
|
||||
drain(ws) {
|
||||
server.ws("drain", ws);
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
|
|
|
|||
|
|
@ -52,34 +52,45 @@ export const apiProxy = (api_url: string) => {
|
|||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let actionUrl = api_ref.apiEntry[actionName].url;
|
||||
const actionParams = api_ref.apiEntry[actionName].args;
|
||||
if (actionUrl && actionParams) {
|
||||
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)) {
|
||||
let actionUrl = api_ref.apiEntry[actionName].url;
|
||||
const actionParams = api_ref.apiEntry[actionName].args;
|
||||
if (actionUrl && actionParams) {
|
||||
if (rest.length > 0 && actionParams.length > 0) {
|
||||
for (const [idx, p] of Object.entries(rest)) {
|
||||
const paramName = actionParams[parseInt(idx)];
|
||||
if (
|
||||
!!p &&
|
||||
typeof p !== "string" &&
|
||||
typeof p !== "number"
|
||||
actionParams &&
|
||||
actionParams.includes(paramName)
|
||||
) {
|
||||
continue;
|
||||
if (
|
||||
!!p &&
|
||||
typeof p !== "string" &&
|
||||
typeof p !== "number"
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
actionUrl = actionUrl.replace(
|
||||
`:${paramName}?`,
|
||||
p + ""
|
||||
);
|
||||
actionUrl = actionUrl.replace(
|
||||
`:${paramName}`,
|
||||
p + ""
|
||||
);
|
||||
}
|
||||
actionUrl = actionUrl.replace(`:${paramName}?`, p + "");
|
||||
actionUrl = actionUrl.replace(`:${paramName}`, p + "");
|
||||
}
|
||||
|
||||
const url = `${base_url}${actionUrl}`;
|
||||
|
||||
const result = await fetchSendApi(url, rest);
|
||||
resolve(result);
|
||||
} else {
|
||||
console.error(`API Not Found: ${actionName.toString()}`);
|
||||
}
|
||||
|
||||
const url = `${base_url}${actionUrl}`;
|
||||
|
||||
const result = await fetchSendApi(url, rest);
|
||||
resolve(result);
|
||||
} else {
|
||||
console.error(`API Not Found: ${actionName.toString()}`);
|
||||
reject("Failed to load API: " + base_url);
|
||||
}
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
|
|
|||
|
|
@ -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,7 +168,9 @@ export const EdApiServer = forwardRef<
|
|||
local.api_url.startsWith("http://") ||
|
||||
local.api_url.startsWith("https://")
|
||||
) {
|
||||
local.api_url = trim(local.api_url, "/");
|
||||
if (local.api_url.length > 8) {
|
||||
local.api_url = trim(local.api_url, "/");
|
||||
}
|
||||
}
|
||||
local.render();
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"linter": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue