diff --git a/internal/content/content-deploy.ts b/internal/content/content-deploy.ts index 1bc2def..83d0d03 100644 --- a/internal/content/content-deploy.ts +++ b/internal/content/content-deploy.ts @@ -14,6 +14,7 @@ export const prasi_content_deploy: PrasiContent = { await loadCurrentDeploy(ts); } }, + async started() {}, async staticFile(ctx) {}, async route(ctx) {}, }; diff --git a/internal/content/content-ipc.ts b/internal/content/content-ipc.ts index f44f21c..95a5945 100644 --- a/internal/content/content-ipc.ts +++ b/internal/content/content-ipc.ts @@ -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) { diff --git a/internal/content/content.ts b/internal/content/content.ts index 25a9029..db84e92 100644 --- a/internal/content/content.ts +++ b/internal/content/content.ts @@ -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; }; diff --git a/internal/content/types.ts b/internal/content/types.ts index a8406de..f357bb5 100644 --- a/internal/content/types.ts +++ b/internal/content/types.ts @@ -3,6 +3,7 @@ import type { ServerCtx } from "utils/server-ctx"; export type PrasiContent = { prepare: (site_id: string) => void | Promise; init: () => Promise; + started: () => Promise; staticFile: (ctx: ServerCtx) => Promise; route: (ctx: ServerCtx) => Promise; }; diff --git a/internal/server/server.ts b/internal/server/server.ts index 048724b..e0e6292 100644 --- a/internal/server/server.ts +++ b/internal/server/server.ts @@ -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) { diff --git a/internal/utils/global.ts b/internal/utils/global.ts index 80bcc75..7610bae 100644 --- a/internal/utils/global.ts +++ b/internal/utils/global.ts @@ -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: {