Skip to content

Commit

Permalink
release: 1.2.0
Browse files Browse the repository at this point in the history
debug 404 page
  • Loading branch information
i007c committed Oct 7, 2024
1 parent 66c5914 commit b4bbcf6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.22
1.2.0
10 changes: 1 addition & 9 deletions config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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' *";
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<minijinja::Environment<'static>>| web::not_found(env),
));
}

#[cfg(unix)]
Expand Down
12 changes: 10 additions & 2 deletions src/web.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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}"
))
Expand Down Expand Up @@ -267,6 +269,11 @@ Sitemap: https://heydari-mi.com/sitemap.xml
)
}

pub async fn not_found(env: Data<Environment<'static>>) -> 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();
Expand All @@ -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())
}

0 comments on commit b4bbcf6

Please sign in to comment.