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.

162 lines (161 loc) 5.05 kB
/** * Route Patterns * * This file provides pre-defined route patterns for common use cases. * These patterns can be used as templates for creating route configurations. */ import type { IRouteConfig } from '../models/route-types.js'; /** * Create a basic HTTP route configuration */ export declare function createHttpRoute(domains: string | string[], target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number); }, options?: Partial<IRouteConfig>): IRouteConfig; /** * Create an HTTPS route with TLS termination */ export declare function createHttpsTerminateRoute(domains: string | string[], target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number); }, options?: Partial<IRouteConfig> & { certificate?: 'auto' | { key: string; cert: string; }; reencrypt?: boolean; }): IRouteConfig; /** * Create an HTTPS route with TLS passthrough */ export declare function createHttpsPassthroughRoute(domains: string | string[], target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number); }, options?: Partial<IRouteConfig>): IRouteConfig; /** * Create an HTTP to HTTPS redirect route */ export declare function createHttpToHttpsRedirect(domains: string | string[], options?: Partial<IRouteConfig> & { redirectCode?: 301 | 302 | 307 | 308; preservePath?: boolean; }): IRouteConfig; /** * Create a complete HTTPS server with redirect from HTTP */ export declare function createCompleteHttpsServer(domains: string | string[], target: { host: string | string[]; port: number | 'preserve' | ((ctx: any) => number); }, options?: Partial<IRouteConfig> & { certificate?: 'auto' | { key: string; cert: string; }; tlsMode?: 'terminate' | 'passthrough' | 'terminate-and-reencrypt'; redirectCode?: 301 | 302 | 307 | 308; }): IRouteConfig[]; /** * Create an API Gateway route pattern * @param domains Domain(s) to match * @param apiBasePath Base path for API endpoints (e.g., '/api') * @param target Target host and port * @param options Additional route options * @returns API route configuration */ export declare function createApiGatewayRoute(domains: string | string[], apiBasePath: string, target: { host: string | string[]; port: number; }, options?: { useTls?: boolean; certificate?: 'auto' | { key: string; cert: string; }; addCorsHeaders?: boolean; [key: string]: any; }): IRouteConfig; /** * Create a WebSocket route pattern * @param domains Domain(s) to match * @param target WebSocket server host and port * @param options Additional route options * @returns WebSocket route configuration */ export declare function createWebSocketRoute(domains: string | string[], target: { host: string | string[]; port: number; }, options?: { useTls?: boolean; certificate?: 'auto' | { key: string; cert: string; }; path?: string; [key: string]: any; }): IRouteConfig; /** * Create a load balancer route pattern * @param domains Domain(s) to match * @param backends Array of backend servers * @param options Additional route options * @returns Load balancer route configuration */ export declare function createLoadBalancerRoute(domains: string | string[], backends: Array<{ host: string; port: number; }>, options?: { useTls?: boolean; certificate?: 'auto' | { key: string; cert: string; }; algorithm?: 'round-robin' | 'least-connections' | 'ip-hash'; healthCheck?: { path: string; interval: number; timeout: number; unhealthyThreshold: number; healthyThreshold: number; }; [key: string]: any; }): IRouteConfig; /** * Create a rate limiting route pattern * @param baseRoute Base route to add rate limiting to * @param rateLimit Rate limiting configuration * @returns Route with rate limiting */ export declare function addRateLimiting(baseRoute: IRouteConfig, rateLimit: { maxRequests: number; window: number; keyBy?: 'ip' | 'path' | 'header'; headerName?: string; errorMessage?: string; }): IRouteConfig; /** * Create a basic authentication route pattern * @param baseRoute Base route to add authentication to * @param auth Authentication configuration * @returns Route with basic authentication */ export declare function addBasicAuth(baseRoute: IRouteConfig, auth: { users: Array<{ username: string; password: string; }>; realm?: string; excludePaths?: string[]; }): IRouteConfig; /** * Create a JWT authentication route pattern * @param baseRoute Base route to add JWT authentication to * @param jwt JWT authentication configuration * @returns Route with JWT authentication */ export declare function addJwtAuth(baseRoute: IRouteConfig, jwt: { secret: string; algorithm?: string; issuer?: string; audience?: string; expiresIn?: number; excludePaths?: string[]; }): IRouteConfig;