@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
192 lines • 4.34 kB
TypeScript
/**
* @module runtime/app-core
* @description Main application orchestrator for Gati framework
*/
import type { RouteManager } from './route-manager.js';
import type { Handler, GlobalContext, Middleware, ErrorMiddleware } from './types/index.js';
import type { LoggerOptions } from './logger.js';
/**
* Application configuration options for scalable deployment
*/
export interface AppConfig {
/**
* Port to listen on
* @default 3000
*/
port?: number;
/**
* Host to bind to
* @default 'localhost'
*/
host?: string;
/**
* Server timeout in milliseconds
* @default 30000
*/
timeout?: number;
/**
* Enable request logging
* @default true
*/
logging?: boolean;
/**
* Logger configuration
*/
logger?: LoggerOptions;
/**
* Clustering configuration
*/
cluster?: {
enabled: boolean;
workers?: number;
};
/**
* Performance optimization settings
*/
performance?: {
keepAliveTimeout: number;
maxConnections: number;
compression: boolean;
bodyLimit: string;
};
/**
* Distributed tracing configuration
*/
tracing?: {
enabled: boolean;
serviceName: string;
endpoint?: string;
};
/**
* External service configurations
*/
services?: {
redis?: {
url: string;
poolSize: number;
};
database?: {
url: string;
poolMin: number;
poolMax: number;
};
};
/**
* Instance metadata for distributed deployment
*/
instance?: {
id: string;
region: string;
zone: string;
};
/**
* Playground configuration
* @default false
*/
playground?: boolean | {
enabled: boolean;
port?: number;
wsPort?: number;
debugMode?: boolean;
};
}
/**
* Main Gati application class
*/
export declare class GatiApp {
private server;
private router;
private middleware;
private gctx;
private config;
private isShuttingDown;
private activeRequests;
private logger;
constructor(config?: AppConfig);
/**
* Register a middleware function
*/
use(middleware: Middleware): void;
/**
* Register an error handling middleware
*/
useError(middleware: ErrorMiddleware): void;
/**
* Register a GET route
*/
get(path: string, handler: Handler): void;
/**
* Register a POST route
*/
post(path: string, handler: Handler): void;
/**
* Register a PUT route
*/
put(path: string, handler: Handler): void;
/**
* Register a PATCH route
*/
patch(path: string, handler: Handler): void;
/**
* Register a DELETE route
*/
delete(path: string, handler: Handler): void;
/**
* Register a route dynamically
*/
registerRoute(method: string, path: string, handler: Handler): void;
/**
* Unregister a route
*/
unregisterRoute(method: string, path: string): void;
/**
* Start the HTTP server
*/
listen(): Promise<void>;
/**
* Stop the HTTP server gracefully
* Waits for active requests to complete before shutting down
*/
close(): Promise<void>;
/**
* Parse request body based on Content-Type
*/
private parseRequestBody;
/**
* Handle incoming HTTP requests
*/
private handleRequest;
/**
* Create default logging middleware
*/
private createLoggingMiddleware;
/**
* Create default error handler
*/
private createDefaultErrorHandler;
/**
* Get the current configuration
*/
getConfig(): Readonly<AppConfig>;
/**
* Check if server is running
*/
isRunning(): boolean;
/**
* Get global context (for module initialization)
*/
getGlobalContext(): GlobalContext;
/**
* Get route manager (for clearing routes)
*/
getRouteManager(): RouteManager;
/**
* Extract session ID from cookie header
*/
private extractSessionFromCookie;
}
/**
* Create a new Gati application
*/
export declare function createApp(config?: AppConfig): GatiApp;
//# sourceMappingURL=app-core.d.ts.map