checkpoint

This commit is contained in:
Rizky 2024-12-20 14:31:50 +07:00
parent d12b850a75
commit fa9cbf5f12
4 changed files with 36 additions and 29 deletions

View File

@ -0,0 +1,3 @@
export const ipcSend = (
msg: { type: "init" } | { type: "ready"; port: number }
) => {};

View File

@ -3,6 +3,7 @@ import { g, startup } from "utils/global";
import { prasi_content_ipc } from "../content/content-ipc";
import { prasi_content_deploy } from "../content/content-deploy";
import { loadCurrentDeploy } from "../content/deploy/load";
import { ipcSend } from "../content/ipc/send";
startup("site", async () => {
await config.init("site:site.json");
@ -10,19 +11,27 @@ startup("site", async () => {
g.content = g.ipc ? prasi_content_ipc : prasi_content_deploy;
if (g.ipc) {
ipcSend({ type: "init" });
process.on("message", (msg: { type: "start" }) => {
if (g.mode === "site") {
if (msg.type === "start") {
g.server = Bun.serve({
fetch(request, server) {},
websocket: { message(ws, message) {} },
});
}
}
});
} else {
const ts = config.current?.deploy.current;
if (ts) {
await loadCurrentDeploy(ts);
}
}
g.server = Bun.serve({
fetch(request, server) {},
websocket: { message(ws, message) {} },
});
if (g.ipc) {
g.server = Bun.serve({
fetch(request, server) {},
websocket: { message(ws, message) {} },
});
}
}
});

View File

@ -2,7 +2,7 @@ import { fs } from "utils/fs";
import { g } from "utils/global";
import { spawn } from "utils/spawn";
export const startServer = (arg: { site_id: string; mode: "dev" | "prod" }) => {
export const startServer = (arg: { mode: "dev" | "prod" }) => {
if (g.mode === "supervisor") {
g.supervisor = {
process: spawn({

View File

@ -14,29 +14,24 @@ startup("supervisor", async () => {
console.log(`${c.green}Prasi Server:${c.esc} ${fs.path("site:")}`);
await config.init("site:site.json");
const site_id = config.get("site_id") as string;
if (!site_id) {
siteLog("No Site Loaded");
} else {
siteLog(`Site ID: ${site_id}`);
if (!is_ipc) {
const site_id = config.get("site_id") as string;
await prasi_content_deploy.prepare(site_id);
if (!is_ipc) {
await prasi_content_deploy.prepare(site_id);
}
await ensureServerReady(is_dev);
await ensureDBReady();
if (is_ipc) {
g.mode = "site";
if (g.mode === "site") g.ipc = true;
if (!site_id) {
siteLog("No Site Loaded");
} else {
siteLog(`Site ID: ${site_id}`);
}
startServer({
site_id,
mode: is_dev ? "dev" : "prod",
});
await ensureDBReady();
} else {
g.mode = "site";
if (g.mode === "site") g.ipc = true;
}
await ensureServerReady(is_dev);
startServer({
mode: is_dev ? "dev" : "prod",
});
});