diff --git a/launcher/src/main.rs b/launcher/src/main.rs index c03af4b7..53de36b2 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -267,17 +267,9 @@ struct Args { #[clap(long, env)] ngrok_authtoken: Option, - /// ngrok domain name where the axum webserver will be available at + /// ngrok edge #[clap(long, env)] - ngrok_domain: Option, - - /// ngrok basic auth username - #[clap(long, env)] - ngrok_username: Option, - - /// ngrok basic auth password - #[clap(long, env)] - ngrok_password: Option, + ngrok_edge: Option, /// Display a lot of information about your runtime environment #[clap(long, short, action)] @@ -900,26 +892,11 @@ fn spawn_webserver( // Ngrok if args.ngrok { - let authtoken = args.ngrok_authtoken.ok_or_else(|| { - tracing::error!("`ngrok-authtoken` must be set when using ngrok tunneling"); - LauncherError::WebserverCannotStart - })?; - router_args.push("--ngrok".to_string()); router_args.push("--ngrok-authtoken".to_string()); - router_args.push(authtoken); - - if let Some(domain) = args.ngrok_domain { - router_args.push("--ngrok-domain".to_string()); - router_args.push(domain); - } - - if let (Some(username), Some(password)) = (args.ngrok_username, args.ngrok_password) { - router_args.push("--ngrok-username".to_string()); - router_args.push(username); - router_args.push("--ngrok-password".to_string()); - router_args.push(password); - } + router_args.push(args.ngrok_authtoken.unwrap()); + router_args.push("--ngrok-edge".to_string()); + router_args.push(args.ngrok_edge.unwrap()); } // Copy current process env @@ -997,7 +974,7 @@ fn terminate(process_name: &str, mut process: Child, timeout: Duration) -> io::R fn main() -> Result<(), LauncherError> { // Pattern match configuration - let args = Args::parse(); + let args: Args = Args::parse(); // Filter events with LOG_LEVEL let env_filter = @@ -1067,6 +1044,20 @@ fn main() -> Result<(), LauncherError> { } } + if args.ngrok { + if args.ngrok_authtoken.is_none() { + return Err(LauncherError::ArgumentValidation( + "`ngrok-authtoken` must be set when using ngrok tunneling".to_string(), + )); + } + + if args.ngrok_edge.is_none() { + return Err(LauncherError::ArgumentValidation( + "`ngrok-edge` must be set when using ngrok tunneling".to_string(), + )); + } + } + // Signal handler let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); diff --git a/router/src/main.rs b/router/src/main.rs index 5aef03dd..059f8692 100644 --- a/router/src/main.rs +++ b/router/src/main.rs @@ -64,11 +64,7 @@ struct Args { #[clap(long, env)] ngrok_authtoken: Option, #[clap(long, env)] - ngrok_domain: Option, - #[clap(long, env)] - ngrok_username: Option, - #[clap(long, env)] - ngrok_password: Option, + ngrok_edge: Option, } fn main() -> Result<(), RouterError> { @@ -96,9 +92,7 @@ fn main() -> Result<(), RouterError> { cors_allow_origin, ngrok, ngrok_authtoken, - ngrok_domain, - ngrok_username, - ngrok_password, + ngrok_edge, } = args; // Validate args @@ -274,9 +268,7 @@ fn main() -> Result<(), RouterError> { cors_allow_origin, ngrok, ngrok_authtoken, - ngrok_domain, - ngrok_username, - ngrok_password, + ngrok_edge, ) .await?; Ok(()) diff --git a/router/src/server.rs b/router/src/server.rs index 8ca463c2..bfeee375 100644 --- a/router/src/server.rs +++ b/router/src/server.rs @@ -524,9 +524,7 @@ pub async fn run( allow_origin: Option, ngrok: bool, ngrok_authtoken: Option, - ngrok_domain: Option, - ngrok_username: Option, - ngrok_password: Option, + ngrok_edge: Option, ) -> Result<(), axum::BoxError> { // OpenAPI documentation #[derive(OpenApi)] @@ -696,32 +694,25 @@ pub async fn run( #[cfg(feature = "ngrok")] { use ngrok::config::TunnelBuilder; - use ngrok::tunnel::UrlTunnel; let _ = addr; let authtoken = ngrok_authtoken.expect("`ngrok-authtoken` must be set when using ngrok tunneling"); - let mut tunnel = ngrok::Session::builder() + let edge = ngrok_edge.expect("`ngrok-edge` must be set when using ngrok tunneling"); + + let tunnel = ngrok::Session::builder() .authtoken(authtoken) .connect() .await .unwrap() - .http_endpoint(); - - if let Some(domain) = ngrok_domain { - tunnel = tunnel.domain(domain); - } - - if let (Some(username), Some(password)) = (ngrok_username, ngrok_password) { - tunnel = tunnel.basic_auth(username, password); - } + .labeled_tunnel() + .label("edge", edge); let listener = tunnel.listen().await.unwrap(); // Run server - tracing::info!("Ingress URL: {:?}", listener.url()); axum::Server::builder(listener) .serve(app.into_make_service()) //Wait until all requests are finished to shut down