@push.rocks/smartproxy
Version:
A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.
118 lines (117 loc) • 4.2 kB
TypeScript
import * as plugins from '../plugins.js';
import { type INetworkProxyOptions, type IReverseProxyConfig } from './classes.np.types.js';
import { type IMetricsTracker } from './classes.np.requesthandler.js';
import { Port80Handler } from '../port80handler/classes.port80handler.js';
/**
* NetworkProxy provides a reverse proxy with TLS termination, WebSocket support,
* automatic certificate management, and high-performance connection pooling.
*/
export declare class NetworkProxy implements IMetricsTracker {
options: INetworkProxyOptions;
proxyConfigs: IReverseProxyConfig[];
httpsServer: plugins.https.Server;
private certificateManager;
private connectionPool;
private requestHandler;
private webSocketHandler;
private router;
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 NetworkProxy instance
*/
constructor(optionsArg: INetworkProxyOptions);
/**
* Implements IMetricsTracker interface to increment request counters
*/
incrementRequestsServed(): void;
/**
* Implements IMetricsTracker interface to increment failed request counters
*/
incrementFailedRequests(): void;
/**
* Returns the port number this NetworkProxy is listening on
* Useful for PortProxy 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 PortProxy to determine which NetworkProxy to use for load balancing
*/
getMetrics(): any;
/**
* Sets an external Port80Handler for certificate management
* This allows the NetworkProxy to use a centrally managed Port80Handler
* instead of creating its own
*
* @param handler The Port80Handler instance to use
*/
setExternalPort80Handler(handler: Port80Handler): void;
/**
* Starts the proxy server
*/
start(): Promise<void>;
/**
* Sets up tracking of TCP connections
*/
private setupConnectionTracking;
/**
* Sets up metrics collection
*/
private setupMetricsCollection;
/**
* Updates proxy configurations
*/
updateProxyConfigs(proxyConfigsArg: plugins.tsclass.network.IReverseProxyConfig[]): Promise<void>;
/**
* Converts PortProxy domain configurations to NetworkProxy configs
* @param domainConfigs PortProxy domain configs
* @param sslKeyPair Default SSL key pair to use if not specified
* @returns Array of NetworkProxy configs
*/
convertPortProxyConfigs(domainConfigs: Array<{
domains: string[];
targetIPs?: string[];
allowedIPs?: string[];
}>, sslKeyPair?: {
key: string;
cert: string;
}): plugins.tsclass.network.IReverseProxyConfig[];
/**
* 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>;
/**
* Gets all proxy configurations currently in use
*/
getProxyConfigs(): plugins.tsclass.network.IReverseProxyConfig[];
}