import { Server } from 'http'; import type { Express } from 'express'; import { SSEManager } from '../http/sse-connection-manager.js'; /** * Options for starting a server */ export interface StartServerOptions { /** Service name for logging */ name?: string; /** Port to listen on (default: from config) */ port?: number; /** SSE manager for graceful shutdown */ sseManager?: SSEManager; /** Shutdown timeout in milliseconds (default: 15000) */ shutdownTimeoutMs?: number; /** Callback after server starts */ onStart?: (port: number) => void; /** Callback before shutdown */ onShutdown?: () => Promise; /** Runs before database check (e.g., initialize external connections) */ onBeforeStart?: () => Promise; /** Custom database health check, or false to skip. Default: PostgreSQL testConnection */ testDatabase?: (() => Promise) | false; /** Custom database close, or false to skip. Default: PostgreSQL closeConnection */ closeDatabase?: (() => Promise) | false; } /** * Result of starting a server */ export interface StartServerResult { /** HTTP server instance */ server: Server; /** Port the server is listening on */ port: number; /** Function to manually trigger shutdown */ shutdown: () => Promise; } /** * Start an Express server with graceful shutdown handling * * Features: * - Automatic database connection testing * - Graceful shutdown on SIGINT/SIGTERM * - SSE connection cleanup * - Configurable shutdown timeout * * @param app - Express application * @param options - Server options * @returns Server instance and control functions * * @example * ```typescript * const { app, sseManager } = createApp(); * * app.post('/api/resource', requireAuth, handler); * * await startServer(app, { * name: 'My Microservice', * sseManager, * onStart: (port) => console.log(`Listening on ${port}`), * }); * ``` */ export declare function startServer(app: Express, options?: StartServerOptions): Promise; /** * Simple server start wrapper with error handling * * @param app - Express application * @param options - Server options * * @example * ```typescript * const { app, sseManager } = createApp(); * app.post('/api/resource', handler); * * void runServer(app, { name: 'My Service', sseManager }); * ``` */ export declare function runServer(app: Express, options?: StartServerOptions): void;