style(i18n): translate all code and comments to English
Rename French identifiers to English across all source files: - validate_cidr / validate_ip_in_network (was valider_*) - known_protocol (was protocole_connu) - counter / doubled (was compteur / double) - InvalidCidr / InvalidIp / IpOutsideNetwork (was *Invalide / *HorsReseau) - test names and error messages All comments, doc strings, .expect() messages, and tracing logs converted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
77
src/main.rs
77
src/main.rs
@@ -1,92 +1,91 @@
|
||||
// main.rs — Point d'entrée du serveur Axum
|
||||
// main.rs — Axum server entry point
|
||||
//
|
||||
// Ce fichier est compilé UNIQUEMENT en mode "ssr" (Server-Side Rendering).
|
||||
// `#[cfg(feature = "ssr")]` est l'équivalent d'un `#ifdef` en C :
|
||||
// le code qu'il protège n'existe pas dans le bundle WASM.
|
||||
// This file is compiled ONLY when the "ssr" feature is enabled.
|
||||
// `#[cfg(feature = "ssr")]` works like `#ifdef` in C:
|
||||
// the guarded code does not exist in the WASM bundle.
|
||||
//
|
||||
// Pour lancer le serveur :
|
||||
// Run the server:
|
||||
// cargo run --features ssr
|
||||
//
|
||||
// Pour lancer avec des logs détaillés :
|
||||
// Run with verbose logs:
|
||||
// RUST_LOG=debug cargo run --features ssr
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[tokio::main]
|
||||
// `#[tokio::main]` transforme `fn main()` synchrone en une fonction asynchrone,
|
||||
// gérée par le runtime Tokio. Sans ça, Rust ne sait pas exécuter du code `async`.
|
||||
// `#[tokio::main]` turns the synchronous `fn main()` into an async function
|
||||
// managed by the Tokio runtime. Without it, Rust cannot execute `async` code.
|
||||
async fn main() {
|
||||
use axum::Router;
|
||||
use leptos::config::get_configuration;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use leptos::view;
|
||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||
use rust_ipam::{
|
||||
app::{App, Shell},
|
||||
server::{config::AppConfig, routes::not_found_handler},
|
||||
};
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
// Initialise les logs structurés.
|
||||
// tracing::info!(), tracing::warn!(), etc. n'affichent rien sans cet initialisateur.
|
||||
// RUST_LOG=debug cargo run --features ssr → active les logs debug
|
||||
// Initialize structured logging.
|
||||
// tracing::info!(), tracing::warn!(), etc. produce no output without this.
|
||||
// RUST_LOG=debug cargo run --features ssr → enables debug-level logs
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()),
|
||||
)
|
||||
.init();
|
||||
|
||||
tracing::info!("Démarrage du serveur Rust IPAM...");
|
||||
tracing::info!("Starting Rust IPAM server...");
|
||||
|
||||
// Charge la configuration depuis .env / variables d'environnement.
|
||||
// On arrête le serveur immédiatement si la config est invalide — il ne peut
|
||||
// pas fonctionner sans savoir à quelle base de données se connecter.
|
||||
// Load configuration from environment variables / .env file.
|
||||
// The server cannot start without knowing which database to connect to,
|
||||
// so we abort immediately on any configuration error.
|
||||
let app_config = AppConfig::from_env()
|
||||
.expect("Erreur de configuration — vérifier le fichier .env");
|
||||
.expect("Configuration error — check your .env file");
|
||||
|
||||
tracing::info!("Base de données : {} ({})", app_config.backend, app_config.database_url);
|
||||
tracing::info!("Database: {} ({})", app_config.backend, app_config.database_url);
|
||||
|
||||
// `Some("Cargo.toml")` indique à Leptos de lire la section
|
||||
// [package.metadata.leptos] du Cargo.toml pour la configuration
|
||||
// (noms de fichiers, chemins, adresse serveur...).
|
||||
// `Some("Cargo.toml")` tells Leptos to read the [package.metadata.leptos]
|
||||
// section from Cargo.toml (file paths, output names, server address...).
|
||||
let conf = get_configuration(Some("Cargo.toml"))
|
||||
.expect("Impossible de charger la configuration Leptos depuis Cargo.toml");
|
||||
.expect("Failed to load Leptos configuration from Cargo.toml");
|
||||
let leptos_options = conf.leptos_options;
|
||||
let addr = leptos_options.site_addr;
|
||||
|
||||
// Analyse les composants `<Route>` dans `App` pour construire
|
||||
// la liste des URLs que Leptos SSR doit gérer.
|
||||
// Walk all `<Route>` components inside `App` to build the list of URLs
|
||||
// that Leptos SSR must handle.
|
||||
let routes = generate_route_list(App);
|
||||
|
||||
// Construit le routeur Axum avec le pattern builder (chaînage de méthodes).
|
||||
// Build the Axum router using the builder pattern (method chaining).
|
||||
let app = Router::new()
|
||||
// Sert les fichiers statiques compilés par trunk (WASM, JS...).
|
||||
// Trunk les place dans target/site/pkg/ (configuré dans [package.metadata.leptos]).
|
||||
// Serve static files compiled by trunk (WASM, JS...).
|
||||
// Trunk places them in target/site/pkg/ as configured in [package.metadata.leptos].
|
||||
.nest_service("/pkg", ServeDir::new("target/site/pkg"))
|
||||
// Branche les routes Leptos dans Axum.
|
||||
// Pour chaque URL, Axum rend Shell() en HTML et le renvoie au navigateur.
|
||||
// Shell() contient App() qui fournit le contenu de la page.
|
||||
// Mount all Leptos routes into Axum.
|
||||
// For each URL, Axum renders Shell() to HTML and sends it to the browser.
|
||||
// Shell() contains App(), which provides the page content.
|
||||
.leptos_routes(&leptos_options, routes, {
|
||||
// On clone les options pour les capturer dans la closure.
|
||||
// Le `move` transfère la propriété de `leptos_options` dans la closure.
|
||||
// Clone options so the closure can capture them.
|
||||
// `move` transfers ownership of `leptos_options` into the closure.
|
||||
let leptos_options = leptos_options.clone();
|
||||
move || view! { <Shell options=leptos_options.clone()/> }
|
||||
})
|
||||
.fallback(not_found_handler)
|
||||
// Partage les options Leptos avec tous les handlers via le système d'état Axum.
|
||||
// Share Leptos options with all handlers via Axum's state system.
|
||||
.with_state(leptos_options);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&addr)
|
||||
.await
|
||||
.expect(&format!("Impossible d'écouter sur l'adresse {}", addr));
|
||||
.expect(&format!("Failed to bind to address {}", addr));
|
||||
|
||||
tracing::info!("Serveur disponible sur http://{}", addr);
|
||||
tracing::info!("Server listening on http://{}", addr);
|
||||
|
||||
axum::serve(listener, app)
|
||||
.await
|
||||
.expect("Erreur critique du serveur");
|
||||
.expect("Fatal server error");
|
||||
}
|
||||
|
||||
// Ce bloc vide est obligatoire pour que le compilateur trouve un `fn main()`
|
||||
// en mode WASM (où la feature "ssr" n'est pas activée).
|
||||
// En WASM, le vrai point d'entrée est la fonction `hydrate()` dans lib.rs.
|
||||
// This empty block is required so the compiler finds a `fn main()`
|
||||
// when building in WASM mode (where the "ssr" feature is not enabled).
|
||||
// In WASM, the real entry point is `hydrate()` in lib.rs.
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
fn main() {}
|
||||
|
||||
Reference in New Issue
Block a user