Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #48 Added support to pass extra args to cloudflared cli from startTunnel function #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be an array similar to how e.g. puppeteer handles it?

});
```

## Development

- Clone this repository
Expand Down
7 changes: 6 additions & 1 deletion src/cloudflared/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
*/
export function startCloudflaredTunnel(
options: Record<string, string | number | null> = {},
extraArgs = ""
): {
/** The URL of the tunnel */
url: Promise<string>;
Expand All @@ -40,9 +41,13 @@ export function startCloudflaredTunnel(
args.push(`${key}`);
}
}
if (args.length === 1) {
if (!options['--url']) {
args.push("--url", "localhost:8080");
}

if (extraArgs) {
args.push(...extraArgs.split(" "));
}

const child = spawn(cloudflaredBinPath, args, {
stdio: ["ignore", "pipe", "pipe"],
Expand Down
5 changes: 3 additions & 2 deletions src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface TunnelOptions {
protocol?: "http" | "https";
verifyTLS?: boolean;
acceptCloudflareNotice?: boolean;
extraArgs?: string;
}

export interface Tunnel {
Expand Down Expand Up @@ -53,10 +54,10 @@ export async function startTunnel(

const args = [
["--url", url],
opts.verifyTLS ? undefined : ["--no-tls-verify", ""],
opts.verifyTLS ? undefined : ["--no-tls-verify", null],
].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();
Expand Down