()
| 35 | |
| 36 | #[actix_web::main] |
| 37 | async 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. |
| 60 | fn error_handlers() -> ErrorHandlers<BoxBody> { |
nothing calls this directly
no test coverage detected