fix: prevent multiple server address print (#713)

This commit is contained in:
Valerio Ageno
2025-04-09 08:49:01 +02:00
committed by GitHub
parent ac20a83e7e
commit 1adf380798
7 changed files with 59 additions and 16 deletions
+2
View File
@@ -21,6 +21,8 @@ clap = { version = "4.5.4", features = ["derive", "cargo"] }
tracing = "0.1.41"
tracing-subscriber = {version = "0.3.19", features = ["env-filter"]}
miette = "7.2.0"
colored = "2.1.0"
watchexec = "5.0.0"
watchexec-signals = "4.0.0"
watchexec-events = "4.0.0"
+10 -1
View File
@@ -3,6 +3,7 @@ use std::path::Path;
use std::sync::RwLock;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use tuono_internal::tuono_println;
use watchexec_events::Tag;
use watchexec_events::filekind::FileEventKind;
@@ -64,6 +65,14 @@ pub async fn watch(source_builder: SourceBuilder) -> Result<()> {
sp.stop();
_ = term.clear_line();
// Server address log for production
// is done on the server process.
if let Ok(builder) = source_builder.read() {
if let Ok(pm) = process_manager.lock() {
pm.log_server_address(builder.app.config.clone().unwrap_or_default());
}
}
let wx = Watchexec::new(move |mut action| {
let process_manager = process_manager.clone();
// if Ctrl-C is received, quit
@@ -118,7 +127,7 @@ pub async fn watch(source_builder: SourceBuilder) -> Result<()> {
}
if should_reload_rust_server || should_refresh_axum_source {
println!(" Reloading...");
tuono_println!("Reloading...");
if should_refresh_axum_source {
if let Ok(mut builder) = source_builder.write() {
builder.app.collect_routes();
+20
View File
@@ -1,10 +1,15 @@
use std::collections::HashMap;
use clap::crate_version;
use std::path::Path;
use std::sync::Arc;
use tokio::task::JoinHandle;
use colored::Colorize;
use tracing::trace;
use tuono_internal::config::Config;
use tuono_internal::tuono_println;
use watchexec_supervisor::command::{Command, Program};
use watchexec_supervisor::job::{Job, start_job};
@@ -85,6 +90,21 @@ impl ProcessManager {
self.start_process(ProcessId::RunRustDevServer);
}
pub fn log_server_address(&self, config: Config) {
let server_address = format!("{}:{}", config.server.host, config.server.port);
// Format the server address as a valid URL so that it becomes clickable in the CLI
// @see https://github.com/tuono-labs/tuono/issues/460
let server_base_url = format!("http://{}", server_address);
println!();
tuono_println!("⚡ Tuono v{}", crate_version!());
tuono_println!("Development server at: {}\n", server_base_url.blue().bold());
if let Some(origin) = config.server.origin {
tuono_println!("Origin: {}\n", origin.blue().bold());
}
}
pub fn restart_process(&mut self, id: ProcessId) {
trace!("Restarting process {:?}", id);
if let Some((job, _)) = self.processes.get(&id) {
+4 -1
View File
@@ -13,7 +13,10 @@ const MODE: Mode = /*MODE*/;
#[tokio::main]
async fn main() {
tuono_internal_init_v8_platform();
println!("\n ⚡ Tuono v/*VERSION*/");
if MODE == Mode::Prod {
println!("\n ⚡ Tuono v/*VERSION*/");
}
//MAIN_FILE_DEFINITION//
+1
View File
@@ -1 +1,2 @@
pub mod config;
pub mod tuono_println;
@@ -0,0 +1,11 @@
#[macro_export]
/// Log a message in the terminal using the custom tuono formatter.
/// The messages printed with this macro should inform or
/// guide the user.
///
/// The debug/error messages should be printed using the `tracing` crate
macro_rules! tuono_println {
($($arg:tt)*) => {{
println!(" {}", format!($($arg)*));
}};
}
+11 -14
View File
@@ -6,6 +6,7 @@ use colored::Colorize;
use ssr_rs::Ssr;
use tower_http::services::ServeDir;
use tuono_internal::config::Config;
use tuono_internal::tuono_println;
use crate::env::load_env_vars;
use crate::{
@@ -31,23 +32,19 @@ pub struct Server {
impl Server {
fn display_start_message(&self) {
/*
* Format the server address as a valid URL so that it becomes clickable in the CLI
* @see https://github.com/tuono-labs/tuono/issues/460
*/
// Format the server address as a valid URL so that it becomes clickable in the CLI
// @see https://github.com/tuono-labs/tuono/issues/460
let server_base_url = format!("http://{}", self.address);
if self.mode == Mode::Dev {
println!(" Ready at: {}\n", server_base_url.blue().bold());
// In order to avoid multiple logs on `tuono dev`
// the server address prompt for tuono dev is made on the CLI process
if self.mode == Mode::Prod {
tuono_println!("Production server at: {}\n", server_base_url.blue().bold());
if let Some(origin) = &self.origin {
tuono_println!("Origin: {}\n", origin.blue().bold());
}
} else {
println!(
" Production server at: {}\n",
server_base_url.blue().bold()
);
}
if let Some(origin) = &self.origin {
println!(" Origin: {}\n", origin.blue().bold());
tuono_println!("Ready\n");
}
}