From 5d8ec82502ed4a09e3ecda17ba40e3842064356a Mon Sep 17 00:00:00 2001 From: Valerio Ageno <51341197+Valerioageno@users.noreply.github.com> Date: Sun, 10 Nov 2024 11:08:06 +0100 Subject: [PATCH] feat: add log to catch_all routes (#83) --- crates/tuono_lib/src/catch_all.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/tuono_lib/src/catch_all.rs b/crates/tuono_lib/src/catch_all.rs index 39b8a1c9..8b983c95 100644 --- a/crates/tuono_lib/src/catch_all.rs +++ b/crates/tuono_lib/src/catch_all.rs @@ -1,12 +1,15 @@ use crate::{ssr::Js, Payload}; use axum::extract::{Path, Request}; use axum::response::Html; +use colored::*; use std::collections::HashMap; +use tokio::time::Instant; pub async fn catch_all( Path(params): Path>, request: Request, ) -> Html { + let start = Instant::now(); let pathname = request.uri(); let headers = request.headers(); @@ -17,6 +20,18 @@ pub async fn catch_all( let result = Js::render_to_string(Some(&payload)); + let duration = start.elapsed(); + + // TODO: handle 404 error on catch_all route + let http_code = "200"; + + println!( + " GET {} {} in {}ms", + req.uri.path(), + http_code.green(), + duration.as_millis() + ); + match result { Ok(html) => Html(html), _ => Html("500 internal server error".to_string()),