/**
 * WebSocket-aware front-door TCP proxy for dev mode.
 *
 * Bun's node:http has several bugs that prevent Vite's built-in http-proxy
 * from proxying WebSocket upgrades (see linked PRs). Rather than polyfilling
 * those bugs, this module places a lightweight `net.createServer` on the
 * user-facing port. It inspects the first bytes of each TCP connection and
 * routes accordingly:
 *
 * - **WebSocket upgrades to backend paths** → piped directly to Bun backend
 *   (Bun's native `server.upgrade()` works perfectly over raw TCP)
 * - **Everything else** (HTTP requests, Vite HMR WebSocket) → piped to Vite
 *
 * From the browser's perspective there is only one port. Vite and Bun both
 * listen on internal ports that are never exposed.
 *
 * Bun bugs this works around:
 * - https://github.com/oven-sh/bun/pull/27237 (socket.write drops data)
 * - https://github.com/oven-sh/bun/pull/26264 (missing destroySoon)
 * - https://github.com/oven-sh/bun/pull/27859 (http.request upgrade event)
 * - Server-side upgrade socket read broken (HTTP parser doesn't hand off)
 *
 * This entire module can be removed once those Bun PRs are merged and the
 * Vite `ws: true` proxy works natively under Bun.
 *
 * ```
 * Browser ──TCP──▶ net.Server (:3500, user-facing)
 *                     │
 *         ┌───────────┴───────────┐
 *         ▼ (WS upgrade to       ▼ (everything else)
 *          backend paths)
 *   Bun backend (:3501)    Vite server (:3502)
 * ```
 */
import { type Server } from 'node:net';
import type { Logger } from '../../../types';
export interface WsProxyOptions {
    /** Port the front-door proxy listens on (user-facing) */
    port: number;
    /** Port of the Vite dev server (internal) */
    vitePort: number;
    /** Port of the Bun backend server (internal) */
    backendPort: number;
    /** Route path prefixes that should be proxied to the backend */
    routePaths: string[];
    logger: Logger;
}
/**
 * Front-door TCP proxy server.
 *
 * Extends `net.Server` with a `closeAll()` method that destroys all live
 * client + upstream sockets and waits for the listening socket to close.
 * The native `Server.close()` only stops accepting new connections — long-
 * lived piped sockets (Vite HMR WebSocket, backend WS) keep the listener
 * bound until they close on their own. During dev-mode shutdown we want
 * the user-facing port released immediately, so cleanup paths should
 * prefer `closeAll()` over `close()`.
 */
export interface WsProxyServer extends Server {
    closeAll(): Promise<void>;
}
/**
 * Start a front-door TCP proxy that routes WebSocket upgrades to the Bun
 * backend and everything else to Vite. Returns the `net.Server` instance.
 */
export declare function startWsProxy(options: WsProxyOptions): Promise<WsProxyServer>;
//# sourceMappingURL=ws-proxy.d.ts.map