Fix path prefix as /
This commit is contained in:
parent
a56988a601
commit
dd16e5db8a
2 changed files with 13 additions and 5 deletions
|
@ -141,7 +141,7 @@ impl Default for Strings {
|
|||
#[derive(Deserialize)]
|
||||
pub struct StateConfig {
|
||||
/// The path prefix of all routes.
|
||||
#[serde(default = "default_path_prefix")]
|
||||
#[serde(default)]
|
||||
pub path_prefix: String,
|
||||
pub custom_fields: Vec<CustomField>,
|
||||
/// The language tag of the HTML file.
|
||||
|
@ -150,9 +150,6 @@ pub struct StateConfig {
|
|||
#[serde(default)]
|
||||
pub strings: Strings,
|
||||
}
|
||||
fn default_path_prefix() -> String {
|
||||
"/".to_string()
|
||||
}
|
||||
fn default_lang() -> 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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ async fn init(logger_initialized: &mut bool) -> Result<()> {
|
|||
.nest_service("/static", static_service);
|
||||
|
||||
let app = {
|
||||
if path_prefix == "/" {
|
||||
if path_prefix.is_empty() {
|
||||
// No need to nest.
|
||||
routes
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue