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.

116 lines (115 loc) 4.37 kB
import * as plugins from '../../plugins.js'; import type { IReverseProxyConfig } from '../../proxies/http-proxy/models/types.js'; /** * Optional path pattern configuration that can be added to proxy configs */ export interface PathPatternConfig { pathPattern?: string; } export type IPathPatternConfig = PathPatternConfig; /** * Interface for router result with additional metadata */ export interface RouterResult { config: IReverseProxyConfig; pathMatch?: string; pathParams?: Record<string, string>; pathRemainder?: string; } export type IRouterResult = RouterResult; /** * Router for HTTP reverse proxy requests * * 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 ProxyRouter { private reverseProxyConfigs; private defaultConfig?; private pathPatterns; private logger; constructor(configs?: IReverseProxyConfig[], logger?: { error: (message: string, data?: any) => void; warn: (message: string, data?: any) => void; info: (message: string, data?: any) => void; debug: (message: string, data?: any) => void; }); /** * Sets a new set of reverse configs to be routed to * @param reverseCandidatesArg Array of reverse proxy configurations */ setNewProxyConfigs(reverseCandidatesArg: IReverseProxyConfig[]): void; /** * Routes a request based on hostname and path * @param req The incoming HTTP request * @returns The matching proxy config or undefined if no match found */ routeReq(req: plugins.http.IncomingMessage): IReverseProxyConfig; /** * Routes a request with detailed matching information * @param req The incoming HTTP request * @returns Detailed routing result including matched config 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 config for a specific host and path */ private findConfigForHost; /** * 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 proxy configurations * @returns Array of all active configurations */ getProxyConfigs(): IReverseProxyConfig[]; /** * Gets all hostnames that this router is configured to handle * @returns Array of hostnames */ getHostnames(): string[]; /** * Adds a single new proxy configuration * @param config The configuration to add * @param pathPattern Optional path pattern for route matching */ addProxyConfig(config: IReverseProxyConfig, pathPattern?: string): void; /** * Sets a path pattern for an existing config * @param config The existing configuration * @param pathPattern The path pattern to set * @returns Boolean indicating if the config was found and updated */ setPathPattern(config: IReverseProxyConfig, pathPattern: string): boolean; /** * Removes a proxy configuration by hostname * @param hostname The hostname to remove * @returns Boolean indicating whether any configs were removed */ removeProxyConfig(hostname: string): boolean; }