()
| 52 | |
| 53 | #[actix_web::main] |
| 54 | async fn main() -> io::Result<()> { |
| 55 | env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); |
| 56 | |
| 57 | // Handlebars uses a repository for the compiled templates. This object must be shared between |
| 58 | // the application threads, and is therefore passed to the App in an Arc. |
| 59 | let mut handlebars = Handlebars::new(); |
| 60 | |
| 61 | // register template dir with Handlebars registry |
| 62 | handlebars |
| 63 | .register_templates_directory( |
| 64 | "./templates", |
| 65 | DirectorySourceOptions { |
| 66 | tpl_extension: ".html".to_owned(), |
| 67 | hidden: false, |
| 68 | temporary: false, |
| 69 | }, |
| 70 | ) |
| 71 | .unwrap(); |
| 72 | |
| 73 | // register Fluent helper with Handlebars registry |
| 74 | handlebars.register_helper("fluent", Box::new(FluentLoader::new(&*LOCALES))); |
| 75 | |
| 76 | let handlebars = web::Data::new(handlebars); |
| 77 | |
| 78 | HttpServer::new(move || { |
| 79 | App::new() |
| 80 | .wrap(error_handlers()) |
| 81 | .app_data(web::Data::clone(&handlebars)) |
| 82 | .service(index) |
| 83 | .service(user) |
| 84 | }) |
| 85 | .workers(2) |
| 86 | .bind(("127.0.0.1", 8080))? |
| 87 | .run() |
| 88 | .await |
| 89 | } |
| 90 | |
| 91 | // Custom error handlers, to return HTML responses when an error occurs. |
| 92 | fn error_handlers() -> ErrorHandlers<BoxBody> { |
nothing calls this directly
no test coverage detected