1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

chore: fix template location

This commit is contained in:
Rob Ede
2024-03-05 22:30:51 +00:00
parent e5fc327af0
commit c5c208eda7
8 changed files with 22 additions and 10 deletions

View File

@ -6,7 +6,8 @@ edition = "2021"
[dependencies]
actix-web.workspace = true
actix-web-lab.workspace = true
env_logger.workspace = true
fluent-templates = { version = "0.9", features = ["handlebars"] }
handlebars = { version = "5.1", features = ["dir_source"] }
handlebars = { version = "5", features = ["dir_source"] }
serde.workspace = true
serde_json.workspace = true

View File

@ -51,6 +51,8 @@ async fn user(
#[actix_web::main]
async fn main() -> io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
// Handlebars uses a repository for the compiled templates. This object must be shared between
// the application threads, and is therefore passed to the App in an Arc.
let mut handlebars = Handlebars::new();
@ -58,7 +60,7 @@ async fn main() -> io::Result<()> {
// register template dir with Handlebars registry
handlebars
.register_templates_directory(
"./static/templates",
"./templates",
DirectorySourceOptions {
tpl_extension: ".html".to_owned(),
hidden: false,
@ -79,6 +81,7 @@ async fn main() -> io::Result<()> {
.service(index)
.service(user)
})
.workers(2)
.bind(("127.0.0.1", 8080))?
.run()
.await