fix in error codes

This commit is contained in:
Mateusz Gruszczyński
2026-07-22 14:25:18 +02:00
parent ec9f002b81
commit d5ec8a28e7
3 changed files with 20 additions and 4 deletions
+19 -2
View File
@@ -5,12 +5,29 @@ use axum::{
routing::{get, post},
Router,
};
use tower::ServiceBuilder;
use tower::{service_fn, ServiceBuilder};
use tower_http::{services::ServeDir, set_header::SetResponseHeaderLayer, trace::TraceLayer};
use crate::{api, auth, db, state::SharedState, websocket};
use std::convert::Infallible;
pub fn router(state: SharedState, static_dir: &str, upload_max_size_bytes: usize) -> Router {
let asset_version = state.asset_version.clone();
let asset_not_found = service_fn(move |_request| {
let asset_version = asset_version.clone();
async move {
Ok::<_, Infallible>(error_response(
StatusCode::NOT_FOUND,
"404",
"File not found",
"The requested application asset does not exist.",
"/",
"Home page",
&asset_version,
))
}
});
Router::new()
.route("/", get(home))
.route("/p/{slug}", get(pad))
@@ -78,7 +95,7 @@ pub fn router(state: SharedState, static_dir: &str, upload_max_size_bytes: usize
header::CACHE_CONTROL,
HeaderValue::from_static("private, must-revalidate"),
))
.service(ServeDir::new(static_dir)),
.service(ServeDir::new(static_dir).not_found_service(asset_not_found)),
)
.fallback(not_found)
.method_not_allowed_fallback(method_not_allowed)
+1 -1
View File
@@ -54,7 +54,7 @@ impl Config {
upload_max_size_bytes: upload_max_size_mb
.checked_mul(1024 * 1024)
.ok_or("UPLOAD_MAX_SIZE_MB is too large")?,
asset_version: env_var("ASSET_VERSION", env!("CARGO_PKG_VERSION")),
asset_version: env!("CARGO_PKG_VERSION").to_owned(),
smtp,
registration_enabled: env_bool("REGISTRATION_ENABLED", false)?,
frontend_log_level: env_log_level("FRONTEND_LOG_LEVEL", "warn")?,