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.

114 lines (113 loc) 4.04 kB
import * as plugins from '../../plugins.js'; import type { IHttpProxyOptions } from './models/types.js'; import type { IRouteConfig } from '../smart-proxy/models/route-types.js'; import { type IMetricsTracker } from './request-handler.js'; /** * HttpProxy provides a reverse proxy with TLS termination, WebSocket support, * automatic certificate management, and high-performance connection pooling. * Handles all HTTP/HTTPS traffic including redirects, ACME challenges, and static routes. */ export declare class HttpProxy implements IMetricsTracker { toJSON(): any; options: IHttpProxyOptions; routes: IRouteConfig[]; httpsServer: any; private certificateManager; private connectionPool; private requestHandler; private webSocketHandler; private router; private routeManager; private functionCache; private securityManager; socketMap: plugins.lik.ObjectMap<plugins.net.Socket>; activeContexts: Set<string>; connectedClients: number; startTime: number; requestsServed: number; failedRequests: number; private portProxyConnections; private tlsTerminatedConnections; private metricsInterval; private connectionPoolCleanupInterval; private logger; /** * Creates a new HttpProxy instance */ constructor(optionsArg: IHttpProxyOptions); /** * Implements IMetricsTracker interface to increment request counters */ incrementRequestsServed(): void; /** * Implements IMetricsTracker interface to increment failed request counters */ incrementFailedRequests(): void; /** * Returns the port number this HttpProxy is listening on * Useful for SmartProxy to determine where to forward connections */ getListeningPort(): number; /** * Updates the server capacity settings * @param maxConnections Maximum number of simultaneous connections * @param keepAliveTimeout Keep-alive timeout in milliseconds * @param connectionPoolSize Size of the connection pool per backend */ updateCapacity(maxConnections?: number, keepAliveTimeout?: number, connectionPoolSize?: number): void; /** * Returns current server metrics * Useful for SmartProxy to determine which HttpProxy to use for load balancing */ getMetrics(): any; /** * Starts the proxy server */ start(): Promise<void>; /** * Sets up tracking of TCP connections */ private setupConnectionTracking; /** * Sets up metrics collection */ private setupMetricsCollection; /** * Updates the route configurations - this is the primary method for configuring HttpProxy * @param routes The new route configurations to use */ updateRouteConfigs(routes: IRouteConfig[]): Promise<void>; /** * Adds default headers to be included in all responses */ addDefaultHeaders(headersArg: { [key: string]: string; }): Promise<void>; /** * Stops the proxy server */ stop(): Promise<void>; /** * Requests a new certificate for a domain * This can be used to manually trigger certificate issuance * @param domain The domain to request a certificate for * @returns A promise that resolves when the request is submitted (not when the certificate is issued) */ requestCertificate(domain: string): Promise<boolean>; /** * Update certificate for a domain * * This method allows direct updates of certificates from external sources * like Port80Handler or custom certificate providers. * * @param domain The domain to update certificate for * @param certificate The new certificate (public key) * @param privateKey The new private key * @param expiryDate Optional expiry date */ updateCertificate(domain: string, certificate: string, privateKey: string, expiryDate?: Date): void; /** * Gets all route configurations currently in use */ getRouteConfigs(): IRouteConfig[]; }