UNPKG

@zenweb/core

Version:

ZenWeb Core Module - Module loader and Server

70 lines (69 loc) 1.61 kB
import { Server } from 'node:http'; import { Application, CoreOption, LoadedModule, SetupFunction } from './types.js'; export declare class Core { /** * 取得应用名称 * 获取顺序: env.APP_NAME || hostname */ readonly name: string; /** * 启动时间: 毫秒时间戳 */ readonly startTime: number; /** * 取得 Koa 实例 */ readonly app: Application; /** * 已载入的模块 */ readonly loadedModules: LoadedModule[]; /** * 取得 http.Server 实例 */ readonly server: Server; /** * core debug 信息打印 */ readonly debug: import("./util.js").Debugger; /** * 应用是否正在停止中 */ private _stopping; constructor(option?: CoreOption); /** * 安装模块 * @param setup 模块模块安装函数 * @param name 自定义模块名称,不指定则取模块内置名称 */ setup(setup: SetupFunction, name?: string): this; /** * 检查模块是否存在 * @param name 模块名称 */ moduleExists(name: string): boolean; /** * 启动所有模块代码 */ boot(): Promise<this>; /** * 监听端口,默认 7001 */ listen(port?: number): Promise<void>; /** * 关闭端口监听 */ closeListen(): Promise<void>; /** * 启动应用 */ start(port?: number): Promise<void>; /** * 进程型号接收处理 */ private _signalReceiver; /** * 停止应用 */ stop(signal?: string | number): Promise<void>; }