Fix path prefix as /

This commit is contained in:
Mo 2023-02-26 17:02:09 +01:00
parent a56988a601
commit dd16e5db8a
2 changed files with 13 additions and 5 deletions

View file

@ -141,7 +141,7 @@ impl Default for Strings {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct StateConfig { pub struct StateConfig {
/// The path prefix of all routes. /// The path prefix of all routes.
#[serde(default = "default_path_prefix")] #[serde(default)]
pub path_prefix: String, pub path_prefix: String,
pub custom_fields: Vec<CustomField>, pub custom_fields: Vec<CustomField>,
/// The language tag of the HTML file. /// The language tag of the HTML file.
@ -150,9 +150,6 @@ pub struct StateConfig {
#[serde(default)] #[serde(default)]
pub strings: Strings, pub strings: Strings,
} }
fn default_path_prefix() -> String {
"/".to_string()
}
fn default_lang() -> String { fn default_lang() -> String {
"en".to_string() "en".to_string()
} }
@ -208,6 +205,17 @@ impl Config {
); );
}); });
// Trim path prefix and set it to empty if it is /.
config.state_config.path_prefix = {
let path_prefix = config.state_config.path_prefix.trim();
if path_prefix == "/" {
String::default()
} else {
path_prefix.to_string()
}
};
Ok(config) Ok(config)
} }
} }

View file

@ -51,7 +51,7 @@ async fn init(logger_initialized: &mut bool) -> Result<()> {
.nest_service("/static", static_service); .nest_service("/static", static_service);
let app = { let app = {
if path_prefix == "/" { if path_prefix.is_empty() {
// No need to nest. // No need to nest.
routes routes
} else { } else {