import { spawn } from "node:child_process"; import { getTailscaleDnsName } from "./webhook/tailscale.js";
/** * Tunnel configuration for exposing the webhook server.
*/
export interface TunnelConfig { /** Tunnel provider: ngrok, tailscale-serve, or tailscale-funnel */
provider: "ngrok" | "tailscale-serve" | "tailscale-funnel" | "none"; /** Local port to tunnel */
port: number; /** Path prefix for the tunnel (e.g., /voice/webhook) */
path: string; /** ngrok auth token (optional, enables longer sessions) */
ngrokAuthToken?: string; /** ngrok custom domain (paid feature) */
ngrokDomain?: string;
}
/** * Result of starting a tunnel.
*/
export interface TunnelResult { /** The public URL */
publicUrl: string; /** Function to stop the tunnel */
stop: () => Promise<void>; /** Tunnel provider name */
provider: string;
}
/** * Start an ngrok tunnel to expose the local webhook server. * * Uses the ngrok CLI which must be installed: https://ngrok.com/download * * @example * const tunnel = await startNgrokTunnel({ port: 3334, path: '/voice/webhook' }); * console.log('Public URL:', tunnel.publicUrl); * // Later: await tunnel.stop();
*/
export async function startNgrokTunnel(config: {
port: number;
path: string;
authToken?: string;
domain?: string;
}): Promise<TunnelResult> { // Set auth token if provided if (config.authToken) {
await runNgrokCommand(["config", "add-authtoken", config.authToken]);
}
/** * Start a Tailscale serve/funnel tunnel.
*/
export async function startTailscaleTunnel(config: {
mode: "serve" | "funnel";
port: number;
path: string;
}): Promise<TunnelResult> { // Get Tailscale DNS name const dnsName = await getTailscaleDnsName(); if (!dnsName) { thrownew Error("Could not get Tailscale DNS name. Is Tailscale running?");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.