@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.
122 lines (121 loc) • 4 kB
TypeScript
/**
* HTTP types for routing module.
* These were previously in http-proxy and are now self-contained here.
*/
import * as plugins from '../../plugins.js';
import { HttpStatus as ProtocolHttpStatus } from '../../protocols/http/index.js';
/**
* HTTP-specific event types
*/
export declare enum HttpEvents {
REQUEST_RECEIVED = "request-received",
REQUEST_FORWARDED = "request-forwarded",
REQUEST_HANDLED = "request-handled",
REQUEST_ERROR = "request-error"
}
export declare const HttpStatus: {
readonly OK: ProtocolHttpStatus.OK;
readonly MOVED_PERMANENTLY: ProtocolHttpStatus.MOVED_PERMANENTLY;
readonly FOUND: ProtocolHttpStatus.FOUND;
readonly TEMPORARY_REDIRECT: ProtocolHttpStatus.TEMPORARY_REDIRECT;
readonly PERMANENT_REDIRECT: ProtocolHttpStatus.PERMANENT_REDIRECT;
readonly BAD_REQUEST: ProtocolHttpStatus.BAD_REQUEST;
readonly UNAUTHORIZED: ProtocolHttpStatus.UNAUTHORIZED;
readonly FORBIDDEN: ProtocolHttpStatus.FORBIDDEN;
readonly NOT_FOUND: ProtocolHttpStatus.NOT_FOUND;
readonly METHOD_NOT_ALLOWED: ProtocolHttpStatus.METHOD_NOT_ALLOWED;
readonly REQUEST_TIMEOUT: ProtocolHttpStatus.REQUEST_TIMEOUT;
readonly TOO_MANY_REQUESTS: ProtocolHttpStatus.TOO_MANY_REQUESTS;
readonly INTERNAL_SERVER_ERROR: ProtocolHttpStatus.INTERNAL_SERVER_ERROR;
readonly NOT_IMPLEMENTED: ProtocolHttpStatus.NOT_IMPLEMENTED;
readonly BAD_GATEWAY: ProtocolHttpStatus.BAD_GATEWAY;
readonly SERVICE_UNAVAILABLE: ProtocolHttpStatus.SERVICE_UNAVAILABLE;
readonly GATEWAY_TIMEOUT: ProtocolHttpStatus.GATEWAY_TIMEOUT;
};
/**
* Base error class for HTTP-related errors
*/
export declare class HttpError extends Error {
readonly statusCode: number;
constructor(message: string, statusCode?: number);
}
/**
* Error related to certificate operations
*/
export declare class CertificateError extends HttpError {
readonly domain: string;
readonly isRenewal: boolean;
constructor(message: string, domain: string, isRenewal?: boolean);
}
/**
* Error related to server operations
*/
export declare class ServerError extends HttpError {
readonly code?: string | undefined;
constructor(message: string, code?: string | undefined, statusCode?: number);
}
/**
* Error for bad requests
*/
export declare class BadRequestError extends HttpError {
constructor(message: string);
}
/**
* Error for not found resources
*/
export declare class NotFoundError extends HttpError {
constructor(message?: string);
}
/**
* Redirect configuration for HTTP requests
*/
export interface IRedirectConfig {
source: string;
destination: string;
type: number;
preserveQuery?: boolean;
}
/**
* HTTP router configuration
*/
export interface IRouterConfig {
routes: Array<{
path: string;
method?: string;
handler: (req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse) => void | Promise<void>;
}>;
notFoundHandler?: (req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse) => void;
errorHandler?: (error: Error, req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse) => void;
}
/**
* HTTP request method types
*/
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE';
/**
* Helper function to get HTTP status text
*/
export declare function getStatusText(status: number): string;
export interface IDomainOptions {
domainName: string;
sslRedirect: boolean;
acmeMaintenance: boolean;
forward?: {
ip: string;
port: number;
};
acmeForward?: {
ip: string;
port: number;
};
}
export interface IDomainCertificate {
options: IDomainOptions;
certObtained: boolean;
obtainingInProgress: boolean;
certificate?: string;
privateKey?: string;
expiryDate?: Date;
lastRenewalAttempt?: Date;
}
export { HttpError as Port80HandlerError };
export { CertificateError as CertError };