bunnel
Version:
Websocket reverse tunnel
72 lines (69 loc) • 1.86 kB
TypeScript
interface TunnelRequest {
id: string;
method: string;
path: string;
headers: Record<string, string>;
body: string | null;
}
interface TunnelResponse {
id: string;
status: number;
headers: Record<string, string>;
body: string;
}
interface ConnectedMessage {
type: 'connected';
subdomain: string;
}
interface TunnelClientOptions {
/**
* The URL of your local server that will receive the tunneled requests
*/
localServerUrl: string;
/**
* The URL of the tunnel server (remote)
*/
tunnelServerUrl: string;
/**
* Called when the tunnel is closed
* This is kept as a callback since it's an event that happens after setup
*/
onClosed?: () => void;
/**
* Timeout in milliseconds for local server availability check
* Default: 5000 (5 seconds)
*/
serverCheckTimeout?: number;
}
interface ConnectionInfo {
subdomain: string;
tunnelUrl: string;
}
declare class TunnelClient {
private ws;
private localServerUrl;
private tunnelServerUrl;
private serverCheckTimeout;
private options;
constructor(options: TunnelClientOptions);
/**
* Check if the local server is available
* @throws Error if the server is unavailable
*/
checkLocalServerAvailability(): Promise<void>;
/**
* Connect to the tunnel server
* @returns Promise with connection info
* @throws Error if connection fails or local server is unavailable
*/
connect(): Promise<ConnectionInfo>;
/**
* Disconnect from the tunnel server
*/
disconnect(): void;
/**
* Check if connected to the tunnel server
*/
isConnected(): boolean;
}
export { type ConnectedMessage, type ConnectionInfo, TunnelClient, type TunnelClientOptions, type TunnelRequest, type TunnelResponse };