1use cebolla::*;
2
3use poem::{EndpointExt, Route, Server, get, handler, middleware::Tracing, web::Path};
4use snafu::{ResultExt, Whatever};
5
6#[handler]
7fn hello(Path(name): Path<String>) -> String {
8 format!("hello: {name}")
9}
10
11#[tokio::main]
12async fn main() -> Result<(), Whatever> {
13 println!("Connecting to tor network");
14 let tor = Tor::new(TorConfig::default())
15 .await
16 .whatever_context("unable to connect to tor network")?;
17 println!("Connected!");
18 let service = tor
19 .service("hello")
20 .whatever_context("unable to create service")?;
21
22 println!(
23 "Onion address: {}",
24 service.onion_address().unwrap().display_unredacted()
25 );
26
27 let app = Route::new().at("/hello/:name", get(hello)).with(Tracing);
28 Server::new(service)
29 .name("hello-world")
30 .run(app)
31 .await
32 .expect("server error");
33 Ok(())
34}