@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.
56 lines (55 loc) • 2 kB
TypeScript
/**
* Socket Handler Functions
*
* This module provides pre-built socket handlers for common use cases
* like echoing, proxying, HTTP responses, and redirects.
*/
import * as plugins from '../../../plugins.js';
import type { IRouteContext } from '../models/route-types.js';
/**
* Pre-built socket handlers for common use cases
*/
export declare const SocketHandlers: {
/**
* Simple echo server handler
*/
echo: (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* TCP proxy handler
*/
proxy: (targetHost: string, targetPort: number) => (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* Line-based protocol handler
*/
lineProtocol: (handler: (line: string, socket: plugins.net.Socket) => void) => (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* Simple HTTP response handler (for testing)
*/
httpResponse: (statusCode: number, body: string) => (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* Block connection immediately
*/
block: (message?: string) => (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* HTTP block response
*/
httpBlock: (statusCode?: number, message?: string) => (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* HTTP redirect handler
*/
httpRedirect: (locationTemplate: string, statusCode?: number) => (socket: plugins.net.Socket, context: IRouteContext) => void;
/**
* HTTP server handler for ACME challenges and other HTTP needs
*/
httpServer: (handler: (req: {
method: string;
url: string;
headers: Record<string, string>;
body?: string;
}, res: {
status: (code: number) => void;
header: (name: string, value: string) => void;
send: (data: string) => void;
end: () => void;
}) => void) => (socket: plugins.net.Socket, context: IRouteContext) => void;
};