fix main server.js

This commit is contained in:
Rizky 2024-07-05 05:41:58 +07:00
parent b28b0462ff
commit 72e4c71d61
4 changed files with 86 additions and 73 deletions

File diff suppressed because one or more lines are too long

View File

@ -29,7 +29,8 @@ export const initServer = async (
}
code.internal.server[id_site] = {
rebuilding: false, ts: 0,
rebuilding: false,
ts: 0,
ctx: await context({
absWorkingDir: dir.data(root),
entryPoints: ["server.ts"],
@ -102,9 +103,10 @@ export const initServer = async (
} else {
db = global.db;
api = global.api;
}`,
}
`,
},
})
}),
};
code.internal.server[id_site].rebuilding = true;

View File

@ -57,13 +57,14 @@ const serverMain = () => ({
this.handler[site_id] = svr.server;
svr.server.site_id = site_id;
if (typeof svr.server.init === "function") {
await svr.server.init({});
}
Bun.write(
Bun.file(code.path(site_id, "site", "src", "server.log")),
""
);
if (typeof svr.server.init === "function") {
await svr.server.init({});
}
} else {
const file = await Bun.file(server_src_path).text();
const log_path = code.path(site_id, "site", "src", "server.log");

View File

@ -175,9 +175,14 @@ export const fetchSendDb = async (params: any, dburl: string) => {
let result = await cachedQueryResult[hsum].promise;
cached = cachedQueryResult[hsum];
try {
if (typeof result === "string") {
result = JSON.parse(result);
cachedQueryResult[hsum].result = result;
return result;
} else {
cachedQueryResult[hsum].result = result;
return result;
}
} catch (e) {
console.error("DBQuery failed:", result);
}
@ -188,7 +193,12 @@ export const fetchSendDb = async (params: any, dburl: string) => {
let result = await cached.promise;
if (result) {
try {
return JSON.parse(result);
if (typeof result === "string") {
result = JSON.parse(result);
return result;
} else {
return result;
}
} catch (e) {
console.error("DBQuery failed:", result);
}