()
| 36 | |
| 37 | #[actix_web::main] |
| 38 | async fn main() -> io::Result<()> { |
| 39 | env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); |
| 40 | |
| 41 | // Handlebars uses a repository for the compiled templates. This object must be |
| 42 | // shared between the application threads, and is therefore passed to the |
| 43 | // Application Builder as an atomic reference-counted pointer. |
| 44 | let mut handlebars = Handlebars::new(); |
| 45 | handlebars |
| 46 | .register_templates_directory( |
| 47 | "./templates", |
| 48 | DirectorySourceOptions { |
| 49 | tpl_extension: ".html".to_owned(), |
| 50 | hidden: false, |
| 51 | temporary: false, |
| 52 | }, |
| 53 | ) |
| 54 | .unwrap(); |
| 55 | let handlebars_ref = web::Data::new(handlebars); |
| 56 | |
| 57 | HttpServer::new(move || { |
| 58 | App::new() |
| 59 | .wrap(error_handlers()) |
| 60 | .app_data(handlebars_ref.clone()) |
| 61 | .service(index) |
| 62 | .service(user) |
| 63 | }) |
| 64 | .workers(2) |
| 65 | .bind(("127.0.0.1", 8080))? |
| 66 | .run() |
| 67 | .await |
| 68 | } |
| 69 | |
| 70 | // Custom error handlers, to return HTML responses when an error occurs. |
| 71 | fn error_handlers() -> ErrorHandlers<BoxBody> { |
nothing calls this directly
no test coverage detected