diff --git a/examples/actix_example/README.md b/examples/actix_example/README.md index c7ad2171e..a2acf4140 100644 --- a/examples/actix_example/README.md +++ b/examples/actix_example/README.md @@ -13,6 +13,6 @@ Run server with auto-reloading: ```bash -cargo install systemfd +cargo install systemfd cargo-watch systemfd --no-pid -s http::8000 -- cargo watch -x run ``` diff --git a/examples/actix_example/src/main.rs b/examples/actix_example/src/main.rs index ec24095aa..a8f80fd0a 100644 --- a/examples/actix_example/src/main.rs +++ b/examples/actix_example/src/main.rs @@ -158,6 +158,17 @@ async fn delete(data: web::Data, id: web::Path) -> Result, request: HttpRequest) -> Result { + let mut ctx = tera::Context::new(); + ctx.insert("uri", request.uri().path()); + + let template = &data.templates; + let body = template.render("error/404.html.tera", &ctx) + .map_err(|_| error::ErrorInternalServerError("Template error"))?; + + Ok(HttpResponse::Ok().content_type("text/html").body(body)) +} + #[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "debug"); @@ -186,6 +197,7 @@ async fn main() -> std::io::Result<()> { .service(Fs::new("/static", "./static")) .app_data(web::Data::new(state.clone())) .wrap(middleware::Logger::default()) // enable logger + .default_service(web::route().to(not_found)) .configure(init) });