MCPcopy Create free account
hub / github.com/actix/examples / main

Function main

templating/tinytemplate/src/main.rs:37–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35
36#[actix_web::main]
37async fn main() -> std::io::Result<()> {
38 env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
39
40 log::info!("starting HTTP server at http://localhost:8080");
41
42 HttpServer::new(|| {
43 let mut tt = TinyTemplate::new();
44 tt.add_template("index.html", INDEX).unwrap();
45 tt.add_template("user.html", USER).unwrap();
46 tt.add_template("error.html", ERROR).unwrap();
47
48 App::new()
49 .app_data(web::Data::new(tt))
50 .wrap(middleware::Logger::default())
51 .service(web::resource("/").route(web::get().to(index)))
52 .service(web::scope("").wrap(error_handlers()))
53 })
54 .bind(("127.0.0.1", 8080))?
55 .run()
56 .await
57}
58
59// Custom error handlers, to return HTML responses when an error occurs.
60fn error_handlers() -> ErrorHandlers<BoxBody> {

Callers

nothing calls this directly

Calls 2

runMethod · 0.80
error_handlersFunction · 0.70

Tested by

no test coverage detected