use std::net::SocketAddr; use axum::{ extract::ConnectInfo, routing::get, Router, }; use ngrok::{ prelude::*, tunnel::LabeledTunnel, }; #[tokio::main] async fn main() -> anyhow::Result<()> { // build our application with a single route let app = Router::new().route( "/", get( |ConnectInfo(remote_addr): ConnectInfo| async move { format!("Hello, {remote_addr:?}!\r\n") }, ), ); // run it with hyper on localhost:8000 // axum::Server::bind(&"0.0.0.0:8000".parse().unwrap()) // Or with an ngrok tunnel axum::Server::builder(start_tunnel().await?) .serve(app.into_make_service_with_connect_info::()) .await .unwrap(); Ok(()) } async fn start_tunnel() -> anyhow::Result { let sess = ngrok::Session::builder() .authtoken_from_env() .connect() .await?; let tun = sess .labeled_tunnel() // .app_protocol("http2") // .verify_upstream_tls(false) .label("edge", "edghts_") .metadata("example tunnel metadata from rust") .listen() .await?; println!("Labeled tunnel started!"); Ok(tun) }