refactor: improve server maintenance mode logging (#282)
Diff
docs/content/features/maintenance-mode.md | 3 +++
src/maintenance_mode.rs | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
@@ -25,6 +25,9 @@ The value should be an existing local HTML file path. When not provided a generi
!!! tip "Optional"
Remember that either `--maintenance-mode-status` and `--maintenance-mode-file` are optional and can be omitted as needed.
!!! info "Independent path"
The `--maintenance-mode-file` is an independent file path and not relative to the root.
## Example
For instance, the server will respond with a `503 Service Unavailable` status code and a custom message.
@@ -22,13 +22,18 @@ pub fn get_response(
file_path: &Path,
) -> Result<Response<Body>> {
tracing::debug!("server has entered into maintenance mode");
tracing::debug!("maintenance mode file path to use: {}", file_path.display());
let mut body_content = String::new();
if file_path.exists() {
if file_path.is_file() {
body_content = String::from_utf8_lossy(&helpers::read_bytes_default(file_path))
.to_string()
.trim()
.to_owned();
} else {
tracing::debug!(
"maintenance mode file path not found or not a regular file, using a default message"
);
}
if body_content.is_empty() {