diff --git a/VERSION b/VERSION index 2ac1f8d..26aaba0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.22 \ No newline at end of file +1.2.0 diff --git a/config/nginx.conf b/config/nginx.conf index f40e854..8f9f737 100644 --- a/config/nginx.conf +++ b/config/nginx.conf @@ -20,9 +20,6 @@ server { # client_max_body_size 1M; - # error_page 404 /error-404; - # error_page 403 /error-403; - # Security Headers # add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' https://trustseal.enamad.ir https://simurgh.00-team.org https://www.googletagmanager.com https://www.google.com/"; add_header Content-Security-Policy "default-src 'self' 'unsafe-inline' *"; @@ -33,13 +30,8 @@ server { add_header Referrer-Policy "no-referrer-when-downgrade"; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; - error_page 404 /templates/404.html; + error_page 404 /404/; - location = /templates/404.html { - root /var/www/html; - internal; - } - location /static { alias /heydari/static; } diff --git a/src/main.rs b/src/main.rs index 76e572f..46554eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,9 @@ fn config_app(app: &mut ServiceConfig) { .service(admin::product_tag::router()), ), ); - app.service(web::router()); + app.service(web::router()).default_service(actix_web::web::to( + |env: Data>| web::not_found(env), + )); } #[cfg(unix)] diff --git a/src/web.rs b/src/web.rs index 139c556..373e8c7 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1,7 +1,7 @@ use actix_web::dev::HttpServiceFactory; use actix_web::http::header::ContentType; use actix_web::middleware::NormalizePath; -use actix_web::web::{Data, Path, Query}; +use actix_web::web::{self, Data, Path, Query}; use actix_web::{get, routes, FromRequest, HttpRequest, HttpResponse, Scope}; use minijinja::{context, path_loader, Environment}; use serde::{Deserialize, Serialize}; @@ -86,7 +86,9 @@ async fn products( }; #[derive(sqlx::FromRow)] - struct Count { count: i64 } + struct Count { + count: i64, + } let products_count: Count = sqlx::query_as(&format!( "select count(id) as count from products {cond}" )) @@ -267,6 +269,11 @@ Sitemap: https://heydari-mi.com/sitemap.xml ) } +pub async fn not_found(env: Data>) -> Response { + let result = env.get_template("404.html")?.render(())?; + Ok(HttpResponse::NotFound().content_type(ContentType::html()).body(result)) +} + pub fn router() -> impl HttpServiceFactory { let tmpl_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("templates"); let mut tmpl_env = Environment::new(); @@ -284,5 +291,6 @@ pub fn router() -> impl HttpServiceFactory { .service(blog) .service(admin_index) .service(robots) + .service(web::resource("/404/").get(not_found)) .service(super::sitemap::router()) }