UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

63 lines (62 loc) 2.22 kB
/** * HTTP Server - AutoSnippet 2.0 * 基于 Express 框架的 REST API 服务器 * 集成监控、缓存和错误追踪 */ import type { Server } from 'node:http'; import express, { type Application } from 'express'; import { CapabilityProbe } from '../core/capability/CapabilityProbe.js'; import Logger from '../infrastructure/logging/Logger.js'; import { type ErrorTracker } from '../infrastructure/monitoring/ErrorTracker.js'; interface HttpServerConfig { port: number; host: string; enableMonitoring: boolean; cacheMode: string; corsOrigin?: string; [key: string]: unknown; } /** Type for the winston Logger instance returned by Logger.getInstance() */ type AppLogger = ReturnType<typeof Logger.getInstance>; export declare class HttpServer { app: Application; cacheAdapter: unknown; capabilityProbe: CapabilityProbe | null; config: HttpServerConfig; errorTracker: ErrorTracker | null; logger: AppLogger; performanceMonitor: { middleware(): express.RequestHandler; shutdown(): void; } | null; realtimeService: Record<string, unknown> | null; server: Server | null; constructor(config?: Partial<HttpServerConfig>); /** 初始化服务器 */ initialize(): Promise<void>; /** 初始化服务(监控、缓存等) */ initializeServices(): Promise<void>; /** 设置中间件 */ setupMiddleware(): void; /** 注册 Gateway Actions */ registerGatewayActions(): void; /** 设置路由 */ setupRoutes(): void; /** 设置错误处理 */ setupErrorHandling(): void; /** 启动服务器 */ start(): Promise<unknown>; /** 停止服务器 */ stop(): Promise<void>; /** 获取 Express 应用实例 */ getApp(): express.Application; /** * 挂载 Dashboard 静态资源(生产模式:直接托管预构建产物) * 必须在 initialize() + start() 之后调用 * @param distDir dashboard/dist 目录的绝对路径 */ mountDashboard(distDir: string): void; /** 获取服务器实例 */ getServer(): Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse> | null; } export default HttpServer;