fix in error codes
This commit is contained in:
@@ -13,7 +13,6 @@ services:
|
|||||||
STATIC_DIR: ${STATIC_DIR:-/app/static}
|
STATIC_DIR: ${STATIC_DIR:-/app/static}
|
||||||
FILES_DIR: ${FILES_DIR:-/data/files}
|
FILES_DIR: ${FILES_DIR:-/data/files}
|
||||||
UPLOAD_MAX_SIZE_MB: ${UPLOAD_MAX_SIZE_MB:-20}
|
UPLOAD_MAX_SIZE_MB: ${UPLOAD_MAX_SIZE_MB:-20}
|
||||||
ASSET_VERSION: ${ASSET_VERSION:-dev}
|
|
||||||
REGISTRATION_ENABLED: ${REGISTRATION_ENABLED:-false}
|
REGISTRATION_ENABLED: ${REGISTRATION_ENABLED:-false}
|
||||||
RUST_LOG: ${RUST_LOG:-rustpad=info,tower_http=warn}
|
RUST_LOG: ${RUST_LOG:-rustpad=info,tower_http=warn}
|
||||||
FRONTEND_LOG_LEVEL: ${FRONTEND_LOG_LEVEL:-warn}
|
FRONTEND_LOG_LEVEL: ${FRONTEND_LOG_LEVEL:-warn}
|
||||||
|
|||||||
+19
-2
@@ -5,12 +5,29 @@ use axum::{
|
|||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use tower::ServiceBuilder;
|
use tower::{service_fn, ServiceBuilder};
|
||||||
use tower_http::{services::ServeDir, set_header::SetResponseHeaderLayer, trace::TraceLayer};
|
use tower_http::{services::ServeDir, set_header::SetResponseHeaderLayer, trace::TraceLayer};
|
||||||
|
|
||||||
use crate::{api, auth, db, state::SharedState, websocket};
|
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 {
|
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()
|
Router::new()
|
||||||
.route("/", get(home))
|
.route("/", get(home))
|
||||||
.route("/p/{slug}", get(pad))
|
.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,
|
header::CACHE_CONTROL,
|
||||||
HeaderValue::from_static("private, must-revalidate"),
|
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)
|
.fallback(not_found)
|
||||||
.method_not_allowed_fallback(method_not_allowed)
|
.method_not_allowed_fallback(method_not_allowed)
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ impl Config {
|
|||||||
upload_max_size_bytes: upload_max_size_mb
|
upload_max_size_bytes: upload_max_size_mb
|
||||||
.checked_mul(1024 * 1024)
|
.checked_mul(1024 * 1024)
|
||||||
.ok_or("UPLOAD_MAX_SIZE_MB is too large")?,
|
.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,
|
smtp,
|
||||||
registration_enabled: env_bool("REGISTRATION_ENABLED", false)?,
|
registration_enabled: env_bool("REGISTRATION_ENABLED", false)?,
|
||||||
frontend_log_level: env_log_level("FRONTEND_LOG_LEVEL", "warn")?,
|
frontend_log_level: env_log_level("FRONTEND_LOG_LEVEL", "warn")?,
|
||||||
|
|||||||
Reference in New Issue
Block a user