From e9e259d0cfcc331f8887a9d2729e4f6292deb86c Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 23 Aug 2024 11:19:05 +0700 Subject: [PATCH] fix --- app/srv/ws/sync/code/templates/typings/global_d_ts | 4 ++-- app/srv/ws/sync/editor/code/server-main.ts | 10 ++++++---- app/srv/ws/sync/editor/code/util-code.ts | 8 +++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/srv/ws/sync/code/templates/typings/global_d_ts b/app/srv/ws/sync/code/templates/typings/global_d_ts index 3cdd4330..1cbf05b1 100644 --- a/app/srv/ws/sync/code/templates/typings/global_d_ts +++ b/app/srv/ws/sync/code/templates/typings/global_d_ts @@ -50,7 +50,7 @@ declare global { } | undefined; - type PrasiServer = { + export interface PrasiServer extends Record { ws?: WebSocketHandler<{ url: string }>; http: (arg: { url: { raw: URL; pathname: string }; @@ -64,7 +64,7 @@ declare global { prasi: { page_id?: string; params?: Record }; }) => Promise; init?: (arg: { port?: number }) => Promise; - }; + } type IItem = { id: string; diff --git a/app/srv/ws/sync/editor/code/server-main.ts b/app/srv/ws/sync/editor/code/server-main.ts index 8a4a1668..5b23723e 100644 --- a/app/srv/ws/sync/editor/code/server-main.ts +++ b/app/srv/ws/sync/editor/code/server-main.ts @@ -53,6 +53,7 @@ const serverMain = () => ({ try { delete require.cache[server_src_path]; const svr = require(server_src_path); + if (svr && typeof svr.server === "object") { this.handler[site_id] = svr.server; svr.server.site_id = site_id; @@ -160,20 +161,21 @@ const serverMain = () => ({ }, }); -type PrasiServer = { - site_id?: string; +export interface PrasiServer extends Record { ws?: WebSocketHandler<{ url: string }>; http: (arg: { url: { raw: URL; pathname: string }; req: Request; server: Server; - handle: (req: Request) => Promise; mode: "dev" | "prod"; + handle: (req: Request) => Promise; + serveStatic?: any; + serveAPI?: any; index: { head: string[]; body: string[]; render: () => string }; prasi: { page_id?: string; params?: Record }; }) => Promise; init?: (arg: { port?: number }) => Promise; -}; +} const glb = global as unknown as { _server: ReturnType; diff --git a/app/srv/ws/sync/editor/code/util-code.ts b/app/srv/ws/sync/editor/code/util-code.ts index 16d6ca77..a13e9b08 100644 --- a/app/srv/ws/sync/editor/code/util-code.ts +++ b/app/srv/ws/sync/editor/code/util-code.ts @@ -73,7 +73,7 @@ declare global { const db: prisma.PrismaClient & ${prismaExtendType}; - type PrasiServer = { + export interface PrasiServer extends Record { ws?: WebSocketHandler<{ url: string }>; http: (arg: { url: { raw: URL; pathname: string }; @@ -81,10 +81,12 @@ declare global { server: Server; mode: "dev" | "prod"; handle: (req: Request) => Promise; + serveStatic?: any; + serveAPI?: any; index: { head: string[]; body: string[]; render: () => string }; prasi: { page_id?: string; params?: Record }; }) => Promise; - init: (arg: { port?: number }) => Promise; - }; + init?: (arg: { port?: number }) => Promise; + } } `;