UNPKG

@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.

109 lines (108 loc) 3.9 kB
import * as plugins from '../../plugins.js'; import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js'; import type { ILogger } from '../../proxies/http-proxy/models/types.js'; /** * Optional path pattern configuration that can be added to proxy configs */ export interface PathPatternConfig { pathPattern?: string; } /** * Interface for router result with additional metadata */ export interface RouterResult { route: IRouteConfig; pathMatch?: string; pathParams?: Record<string, string>; pathRemainder?: string; } /** * Router for HTTP reverse proxy requests based on route configurations * * Supports the following 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) * * Also supports path pattern matching for each domain: * - Exact path: "/api/users" * - Wildcard paths: "/api/*" * - Path parameters: "/users/:id/profile" */ export declare class RouteRouter { private routes; private defaultRoute?; private pathPatterns; private logger; constructor(routes?: IRouteConfig[], logger?: ILogger); /** * Sets a new set of routes to be routed to * @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 potential wildcard patterns that could match a given hostname * Handles complex patterns like "*.lossless*" or other partial matches * @param hostname The hostname to find wildcard matches for * @returns Array of potential wildcard patterns that could match */ private findWildcardMatches; /** * Find a route for a specific host and path */ private findRouteForHost; /** * Matches a URL path against a pattern * Supports: * - Exact matches: /users/profile * - Wildcards: /api/* (matches any path starting with /api/) * - Path parameters: /users/:id (captures id as a parameter) * * @param path The URL path to match * @param pattern The pattern to match against * @returns Match result with params and remainder, or null if no match */ private matchPath; /** * 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 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; /** * Legacy method for compatibility with ProxyRouter * Converts IReverseProxyConfig to IRouteConfig and calls setRoutes * * @param configs Array of legacy proxy configurations */ setNewProxyConfigs(configs: any[]): void; }