use hyper::Body; use log::info; use thruster::context::basic_hyper_context::{ generate_context, BasicHyperContext as Ctx, HyperRequest, }; use thruster::hyper_server::HyperServer; use thruster::{m, middleware_fn}; use thruster::{App, ThrusterServer}; use thruster::{MiddlewareNext, MiddlewareResult}; #[middleware_fn] async fn plaintext(mut context: Ctx, _next: MiddlewareNext) -> MiddlewareResult { let val = "Hello, World!"; context.body = Body::from(val); Ok(context) } #[middleware_fn] async fn nested_plaintext(mut context: Ctx, _next: MiddlewareNext) -> MiddlewareResult { let val = "(nested) Hello, World!"; context.body = Body::from(val); Ok(context) } fn main() { env_logger::init(); info!("Starting server..."); let nested_app = App::::create(generate_context, ()) .get("/plaintext", m![nested_plaintext]); let app = App::::create(generate_context, ()) .get("/plaintext", m![plaintext]) .router("/nested", nested_app); let server = HyperServer::new(app); server.start("0.0.0.0", 4321); }