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);
|
server.ws("ping", ws, data);
|
||||||
},
|
},
|
||||||
pong(ws, data) {
|
pong(ws, data) {
|
||||||
server.ws("pong", ws, data);
|
server.ws("pong", ws, data);
|
||||||
},
|
},
|
||||||
drain(ws) {
|
drain(ws) {
|
||||||
server.ws("drain", ws);
|
server.ws("drain", ws);
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ declare global {
|
||||||
type PrasiServer = {
|
type PrasiServer = {
|
||||||
ws?: WebSocketHandler<{ url: string }>;
|
ws?: WebSocketHandler<{ url: string }>;
|
||||||
http: (arg: {
|
http: (arg: {
|
||||||
url: URL;
|
url: { raw: URL; pathname: string };
|
||||||
req: Request;
|
req: Request;
|
||||||
server: Server;
|
server: Server;
|
||||||
mode: "dev" | "prod";
|
mode: "dev" | "prod";
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,14 @@ const serverMain = () => ({
|
||||||
return new Response("Upgrade failed :(", { status: 500 });
|
return new Response("Upgrade failed :(", { status: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pathname = `/${arg.url.pathname.split("/").slice(3).join("/")}`;
|
||||||
|
|
||||||
return await handler.http({
|
return await handler.http({
|
||||||
...arg,
|
...arg,
|
||||||
|
url: {
|
||||||
|
pathname,
|
||||||
|
raw: arg.url,
|
||||||
|
},
|
||||||
mode: "dev",
|
mode: "dev",
|
||||||
index: prodIndex(site_id),
|
index: prodIndex(site_id),
|
||||||
});
|
});
|
||||||
|
|
@ -104,7 +110,7 @@ const serverMain = () => ({
|
||||||
type PrasiServer = {
|
type PrasiServer = {
|
||||||
ws?: WebSocketHandler<{ url: string }>;
|
ws?: WebSocketHandler<{ url: string }>;
|
||||||
http: (arg: {
|
http: (arg: {
|
||||||
url: URL;
|
url: { raw: URL; pathname: string };
|
||||||
req: Request;
|
req: Request;
|
||||||
server: Server;
|
server: Server;
|
||||||
handle: (req: Request) => Promise<undefined | Response>;
|
handle: (req: Request) => Promise<undefined | Response>;
|
||||||
|
|
|
||||||
|
|
@ -52,34 +52,45 @@ export const apiProxy = (api_url: string) => {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let actionUrl = api_ref.apiEntry[actionName].url;
|
let actionUrl = api_ref.apiEntry[actionName].url;
|
||||||
const actionParams = api_ref.apiEntry[actionName].args;
|
const actionParams = api_ref.apiEntry[actionName].args;
|
||||||
if (actionUrl && actionParams) {
|
if (actionUrl && actionParams) {
|
||||||
if (rest.length > 0 && actionParams.length > 0) {
|
if (rest.length > 0 && actionParams.length > 0) {
|
||||||
for (const [idx, p] of Object.entries(rest)) {
|
for (const [idx, p] of Object.entries(rest)) {
|
||||||
const paramName = actionParams[parseInt(idx)];
|
const paramName = actionParams[parseInt(idx)];
|
||||||
if (actionParams && actionParams.includes(paramName)) {
|
|
||||||
if (
|
if (
|
||||||
!!p &&
|
actionParams &&
|
||||||
typeof p !== "string" &&
|
actionParams.includes(paramName)
|
||||||
typeof p !== "number"
|
|
||||||
) {
|
) {
|
||||||
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 {
|
} else {
|
||||||
console.error(`API Not Found: ${actionName.toString()}`);
|
reject("Failed to load API: " + base_url);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject(e);
|
reject(e);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ export const EdApiServer = forwardRef<
|
||||||
try {
|
try {
|
||||||
if (dev) {
|
if (dev) {
|
||||||
const vdev = JSON.parse(localStorage.getItem("prasi-dev") || "{}");
|
const vdev = JSON.parse(localStorage.getItem("prasi-dev") || "{}");
|
||||||
if (vdev) {
|
|
||||||
|
if (vdev && Object.keys(vdev).length > 0) {
|
||||||
dev.url = vdev.url;
|
dev.url = vdev.url;
|
||||||
dev.enabled = vdev.enabled;
|
dev.enabled = vdev.enabled;
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +168,9 @@ export const EdApiServer = forwardRef<
|
||||||
local.api_url.startsWith("http://") ||
|
local.api_url.startsWith("http://") ||
|
||||||
local.api_url.startsWith("https://")
|
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();
|
local.render();
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,14 @@ export const apiUrl = function (p: PG): string {
|
||||||
|
|
||||||
export const checkAPI = async (p: PG) => {
|
export const checkAPI = async (p: PG) => {
|
||||||
const url = apiUrl(p);
|
const url = apiUrl(p);
|
||||||
|
|
||||||
if (!url) return "offline";
|
if (!url) return "offline";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!apiRef[url]) apiRef[url] = apiProxy(url) as any;
|
if (!apiRef[url]) apiRef[url] = apiProxy(url) as any;
|
||||||
|
|
||||||
const capi = apiRef[url];
|
const capi = apiRef[url];
|
||||||
|
|
||||||
if (!capi) {
|
if (!capi) {
|
||||||
console.error(`Cannot initialize API for ${url}.`, w.prasiApi[url]);
|
console.error(`Cannot initialize API for ${url}.`, w.prasiApi[url]);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -61,6 +63,7 @@ export const checkAPI = async (p: PG) => {
|
||||||
type: "check",
|
type: "check",
|
||||||
id_site: p.site.id,
|
id_site: p.site.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return { deployable: false, db: "", hasDB: false, domains: [] };
|
return { deployable: false, db: "", hasDB: false, domains: [] };
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"linter": {
|
|
||||||
"enabled": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue