import { Hono } from "hono"; import type { MiddlewareHandler } from "hono"; import type { ProxyRoute } from "../types"; import { HandlerRegistry } from "./registry"; import { type ProxyHostContext } from "./handlers/util"; export declare const FORWARDED_HEADERS_HANDLER_TYPE = "forwarded_headers"; /** * Minimal shape shared by stored route handlers (`HandlerConfig`) and the * catch-all specs passed to the data plane (`ProxyRouteHandlerSpec`). */ export interface HandlerSpecLike { type: string; options?: unknown; } /** * Guarantee a `forwarded_headers` handler at the head of a chain. Stored route * tables (KV / control plane) predate the handler and routinely omit it, which * silently drops the visitor IP: nothing else in the chain stamps * X-Forwarded-For / X-Real-IP, so upstreams see only the proxy hop's own * source address. Chains that already declare it — anywhere in the list — are * returned untouched so their configured options win and nothing is stamped * twice. Prefer `withForwardedHeadersFor`, which also checks that the registry * knows the handler. */ export declare function withForwardedHeaders(handlers: readonly HandlerSpecLike[]): HandlerSpecLike[]; /** * `withForwardedHeaders`, but a no-op unless `registry` knows the handler — a * consumer with a bespoke registry that never registered it would otherwise * get a build-time throw on every route. Every chain the data plane compiles * (per-host routes and the `defaultHandlers` catch-all) goes through here. */ export declare function withForwardedHeadersFor(registry: HandlerRegistry, handlers: readonly HandlerSpecLike[]): HandlerSpecLike[]; /** * Build a Hono app whose route table mirrors the configured proxy routes for * a single host. Compiled once per host (and cached alongside the resolved * host) — see `cache.ts`. When `hostContext` is supplied, every request * served by the compiled app gets `tenant_id`, `custom_domain_id`, and * `domain` set in its Hono context (read with `getProxy*` helpers from * `handlers/util.ts`). Handlers that template against those values * (`dispatch_namespace`) depend on this wiring. * * Every route's handler chain is normalized through * `withForwardedHeadersFor`, so a stored route table that omits * `forwarded_headers` still forwards the visitor IP. * * `defaultHandlers` is a prebuilt middleware chain installed as the catch-all * when no per-host route matches. Pass `undefined` to keep the legacy 404 * "No matching route" behavior. It is built by the caller (`router.ts`), which * applies `withForwardedHeadersFor` to it as well. */ export declare function compileHostApp(routes: ProxyRoute[], registry: HandlerRegistry, hostContext?: ProxyHostContext, defaultHandlers?: MiddlewareHandler[]): Hono;