@push.rocks/smartproxy
Version:
A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.
90 lines (89 loc) • 3.04 kB
TypeScript
import * as plugins from '../../plugins.js';
import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
/**
* Interface for router result with additional metadata
*/
export interface RouterResult {
route: IRouteConfig;
pathMatch?: string;
pathParams?: Record<string, string>;
pathRemainder?: string;
}
/**
* Logger interface for HttpRouter
*/
export interface ILogger {
debug?: (message: string, data?: any) => void;
info: (message: string, data?: any) => void;
warn: (message: string, data?: any) => void;
error: (message: string, data?: any) => void;
}
/**
* Unified HTTP Router for reverse proxy requests
*
* Domain matching patterns:
* - Exact matches: "example.com"
* - Wildcard subdomains: "*.example.com" (matches any subdomain of example.com)
* - TLD wildcards: "example.*" (matches example.com, example.org, etc.)
* - Complex wildcards: "*.lossless*" (matches any subdomain of any lossless domain)
* - Default fallback: "*" (matches any unmatched domain)
*
* Path pattern matching:
* - Exact path: "/api/users"
* - Wildcard paths: "/api/*"
* - Path parameters: "/users/:id/profile"
*/
export declare class HttpRouter {
private routes;
private defaultRoute?;
private logger;
constructor(routes?: IRouteConfig[], logger?: ILogger);
/**
* Sets a new set of routes
* @param routes Array of route configurations
*/
setRoutes(routes: IRouteConfig[]): void;
/**
* Routes a request based on hostname and path
* @param req The incoming HTTP request
* @returns The matching route or undefined if no match found
*/
routeReq(req: plugins.http.IncomingMessage): IRouteConfig | undefined;
/**
* Routes a request with detailed matching information
* @param req The incoming HTTP request
* @returns Detailed routing result including matched route and path information
*/
routeReqWithDetails(req: plugins.http.IncomingMessage): RouterResult | undefined;
/**
* Find the best matching route for a given hostname and path
*/
private findMatchingRoute;
/**
* Gets all currently active route configurations
* @returns Array of all active routes
*/
getRoutes(): IRouteConfig[];
/**
* Gets all hostnames that this router is configured to handle
* @returns Array of unique hostnames
*/
getHostnames(): string[];
/**
* Adds a single new route configuration
* @param route The route configuration to add
*/
addRoute(route: IRouteConfig): void;
/**
* Removes routes by domain pattern
* @param domain The domain pattern to remove routes for
* @returns Boolean indicating whether any routes were removed
*/
removeRoutesByDomain(domain: string): boolean;
/**
* Remove a specific route by reference
* @param route The route to remove
* @returns Boolean indicating if the route was found and removed
*/
removeRoute(route: IRouteConfig): boolean;
}