index : static-web-server.git

ascending towards madness

author Jose Quintana <1700322+joseluisq@users.noreply.github.com> 2023-11-05 6:30:46.0 +00:00:00
committer GitHub <noreply@github.com> 2023-11-05 6:30:46.0 +00:00:00
commit
ab16187271d2bf51a8af797e091cf81de6f8d2c7 [patch]
tree
bc6af7b06a8805f533a6bb749050b7e7a832d118
parent
e89ce29085322d3186eebb59de250ed3f40ab859
download
ab16187271d2bf51a8af797e091cf81de6f8d2c7.tar.gz

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(-)

diff --git a/docs/content/features/maintenance-mode.md b/docs/content/features/maintenance-mode.md
index 696149a..33a241a 100644
--- a/docs/content/features/maintenance-mode.md
+++ b/docs/content/features/maintenance-mode.md
@@ -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.
diff --git a/src/maintenance_mode.rs b/src/maintenance_mode.rs
index 06ea099..4a9414a 100644
--- a/src/maintenance_mode.rs
+++ b/src/maintenance_mode.rs
@@ -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() {