ngrok-axum
Serve an Axum app through an ngrok tunnel with one call:
use ;
async
Setup
- Sign up at ngrok.com and grab an authtoken from the dashboard.
- Set it as an env var:
NGROK_AUTHTOKEN=your_token_here - Add the dependency and call
serve:[] = "0.1" = "0.7" = { = "1", = ["full"] }
You'll get a public URL bound to your ngrok account's default dev domain if you don't specify
one — see examples/basic.rs.
Config
let config = Config ;
serve.await?;
See examples/with_config.rs for a working example.
Multiple endpoints
serve_many opens one endpoint per [Endpoint], each with its own Router and Config, all
on a single session, served concurrently:
use ;
serve_many
.await?;
serve(app, config) is just serve_many(vec![Endpoint { app, config }]) — the one-endpoint
case of the same function. See examples/multi.rs (two distinct domains,
two distinct apps) and examples/pooling.rs (one domain, pooling: true, two apps sharing it with load-balanced routing).
| Field | Type | Description |
|---|---|---|
url |
Option<String> |
Reserved domain for this endpoint. None falls back to the account's default dev domain. |
pooling |
bool |
Opt in to ngrok endpoint pooling — required if another endpoint on the same session would otherwise collide on the same domain. See Collisions below. |
traffic_policy |
Option<String> |
A raw ngrok Traffic Policy document (YAML or JSON) — the mechanism for auth, IP restrictions, header manipulation, webhook verification, and more. The granular builder methods on ngrok-rust's HttpTunnelBuilder (basic_auth, oauth, allow_cidr, etc.) mirror ngrok's old "Edge Modules" system, superseded by Traffic Policy — use this instead. |
binding |
Option<Binding> |
Public / Internal / Kubernetes ingress configuration. Not part of Traffic Policy (checked ngrok's actions reference directly — no equivalent exists), so it stays a standalone field. Internal requires url to end in .internal, enforced by ngrok itself (ERR_NGROK_9029 if it doesn't). |
Development
cargo build
cargo test
cargo run --example basic
See DESIGN.md for the design rationale, prior art check, and everything
confirmed empirically along the way.
License
MIT OR Apache-2.0