checkpoint

This commit is contained in:
Rizky 2024-12-21 12:06:18 +07:00
parent 240d4e6ec1
commit e847a8d747
6 changed files with 15 additions and 8 deletions

View File

@ -14,6 +14,7 @@ export const prasi_content_deploy: PrasiContent = {
await loadCurrentDeploy(ts);
}
},
async started() {},
async staticFile(ctx) {},
async route(ctx) {},
};

View File

@ -19,7 +19,6 @@ export const prasi_content_ipc: PrasiContent = {
if (g.mode === "site" && g.ipc) {
if (msg.type === "start") {
g.ipc.asset = await staticFile(msg.path.asset);
ipcSend({ type: "ready", port: g.server.port });
done();
}
}
@ -29,6 +28,11 @@ export const prasi_content_ipc: PrasiContent = {
}
});
},
async started() {
if (g.mode === "site" && g.server) {
ipcSend({ type: "ready", port: g.server.port });
}
},
async staticFile(ctx) {
const asset = g.mode === "site" && g.ipc?.asset!;
if (asset) {

View File

@ -1,5 +1,5 @@
import { g } from "utils/global";
export const prasiContent = () => {
return g.mode === "site" ? g.content : null;
return g.mode === "site" ? g.prasi : null;
};

View File

@ -3,6 +3,7 @@ import type { ServerCtx } from "utils/server-ctx";
export type PrasiContent = {
prepare: (site_id: string) => void | Promise<void>;
init: () => Promise<void>;
started: () => Promise<void>;
staticFile: (ctx: ServerCtx) => Promise<Response | void>;
route: (ctx: ServerCtx) => Promise<Response | void>;
};

View File

@ -8,15 +8,16 @@ import { prasi_content_ipc } from "../content/content-ipc";
startup("site", async () => {
await config.init("site:site.json");
if (g.mode === "site") {
g.content = g.ipc ? prasi_content_ipc : prasi_content_deploy;
g.prasi = g.ipc ? prasi_content_ipc : prasi_content_deploy;
const content = g.content;
await content.init();
startGlobalServer();
const prasi = g.prasi;
await prasi.init();
await startSiteServer();
await prasi.started();
}
});
const startGlobalServer = async () => {
const startSiteServer = async () => {
if (g.mode === "site") {
g.server = Bun.serve({
async fetch(req, server) {

View File

@ -21,7 +21,7 @@ export const g = (globalThis as any).prasi as unknown as {
asset?: StaticFile;
};
static_cache: any;
content: typeof prasi_content_ipc & typeof prasi_content_deploy;
prasi: typeof prasi_content_ipc & typeof prasi_content_deploy;
site?: {
db?: SiteConfig["db"];
layouts: {