This commit is contained in:
Rizky 2024-08-23 11:19:05 +07:00
parent 5abfb17671
commit e9e259d0cf
3 changed files with 13 additions and 9 deletions

View File

@ -50,7 +50,7 @@ declare global {
} }
| undefined; | undefined;
type PrasiServer = { export interface PrasiServer extends Record<string, any> {
ws?: WebSocketHandler<{ url: string }>; ws?: WebSocketHandler<{ url: string }>;
http: (arg: { http: (arg: {
url: { raw: URL; pathname: string }; url: { raw: URL; pathname: string };
@ -64,7 +64,7 @@ declare global {
prasi: { page_id?: string; params?: Record<string, any> }; prasi: { page_id?: string; params?: Record<string, any> };
}) => Promise<Response>; }) => Promise<Response>;
init?: (arg: { port?: number }) => Promise<void>; init?: (arg: { port?: number }) => Promise<void>;
}; }
type IItem = { type IItem = {
id: string; id: string;

View File

@ -53,6 +53,7 @@ const serverMain = () => ({
try { try {
delete require.cache[server_src_path]; delete require.cache[server_src_path];
const svr = require(server_src_path); const svr = require(server_src_path);
if (svr && typeof svr.server === "object") { if (svr && typeof svr.server === "object") {
this.handler[site_id] = svr.server; this.handler[site_id] = svr.server;
svr.server.site_id = site_id; svr.server.site_id = site_id;
@ -160,20 +161,21 @@ const serverMain = () => ({
}, },
}); });
type PrasiServer = { export interface PrasiServer extends Record<string, any> {
site_id?: string;
ws?: WebSocketHandler<{ url: string }>; ws?: WebSocketHandler<{ url: string }>;
http: (arg: { http: (arg: {
url: { raw: URL; pathname: string }; url: { raw: URL; pathname: string };
req: Request; req: Request;
server: Server; server: Server;
handle: (req: Request) => Promise<undefined | Response>;
mode: "dev" | "prod"; mode: "dev" | "prod";
handle: (req: Request) => Promise<Response>;
serveStatic?: any;
serveAPI?: any;
index: { head: string[]; body: string[]; render: () => string }; index: { head: string[]; body: string[]; render: () => string };
prasi: { page_id?: string; params?: Record<string, any> }; prasi: { page_id?: string; params?: Record<string, any> };
}) => Promise<Response>; }) => Promise<Response>;
init?: (arg: { port?: number }) => Promise<void>; init?: (arg: { port?: number }) => Promise<void>;
}; }
const glb = global as unknown as { const glb = global as unknown as {
_server: ReturnType<typeof serverMain>; _server: ReturnType<typeof serverMain>;

View File

@ -73,7 +73,7 @@ declare global {
const db: prisma.PrismaClient & ${prismaExtendType}; const db: prisma.PrismaClient & ${prismaExtendType};
type PrasiServer = { export interface PrasiServer extends Record<string, any> {
ws?: WebSocketHandler<{ url: string }>; ws?: WebSocketHandler<{ url: string }>;
http: (arg: { http: (arg: {
url: { raw: URL; pathname: string }; url: { raw: URL; pathname: string };
@ -81,10 +81,12 @@ declare global {
server: Server; server: Server;
mode: "dev" | "prod"; mode: "dev" | "prod";
handle: (req: Request) => Promise<Response>; handle: (req: Request) => Promise<Response>;
serveStatic?: any;
serveAPI?: any;
index: { head: string[]; body: string[]; render: () => string }; index: { head: string[]; body: string[]; render: () => string };
prasi: { page_id?: string; params?: Record<string, any> }; prasi: { page_id?: string; params?: Record<string, any> };
}) => Promise<Response>; }) => Promise<Response>;
init: (arg: { port?: number }) => Promise<void>; init?: (arg: { port?: number }) => Promise<void>;
}; }
} }
`; `;