diff --git a/README.md b/README.md index a143998..e162e2e 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,21 @@ Verify local server TLS certificate. Accept cloudflare TOS by default. +### `extraArgs` + +- Default: [] + +Extra CLI arguments to provide to cloudflared. + +Example: + +```ts +const tunnel = await startTunnel({ + port: 3000, + extraArgs: ["--no-autoupdate"] +}); +``` + ## Development - Clone this repository diff --git a/src/cloudflared/tunnel.ts b/src/cloudflared/tunnel.ts index 35e037a..c0c687c 100644 --- a/src/cloudflared/tunnel.ts +++ b/src/cloudflared/tunnel.ts @@ -20,6 +20,7 @@ import { */ export function startCloudflaredTunnel( options: Record = {}, + extraArgs: Array = [], ): { /** The URL of the tunnel */ url: Promise; @@ -40,10 +41,14 @@ export function startCloudflaredTunnel( args.push(`${key}`); } } - if (args.length === 1) { + if (!options["--url"]) { args.push("--url", "localhost:8080"); } + if (Array.isArray(extraArgs)) { + args.push(...extraArgs); + } + const child = spawn(cloudflaredBinPath, args, { stdio: ["ignore", "pipe", "pipe"], }); diff --git a/src/tunnel.ts b/src/tunnel.ts index 8478a13..ceae077 100644 --- a/src/tunnel.ts +++ b/src/tunnel.ts @@ -8,6 +8,7 @@ export interface TunnelOptions { protocol?: "http" | "https"; verifyTLS?: boolean; acceptCloudflareNotice?: boolean; + extraArgs?: Array; } export interface Tunnel { @@ -53,10 +54,13 @@ export async function startTunnel( const args = [ ["--url", url], - opts.verifyTLS ? undefined : ["--no-tls-verify", ""], + opts.verifyTLS ? undefined : ["--no-tls-verify", undefined], ].filter(Boolean) as [string, string][]; - const tunnel = await startCloudflaredTunnel(Object.fromEntries(args)); + const tunnel = await startCloudflaredTunnel( + Object.fromEntries(args), + opts.extraArgs, + ); const cleanup = async () => { await tunnel.stop();