fix: CORS layer — corrige 'serveur injoignable' dans le navigateur
- Ajout CorsLayer::permissive() au router axum - Répond aux requêtes OPTIONS (preflight CORS) - Le header X-API-Key rendait les requêtes non-simples → preflight obligatoire - Sans réponse OPTIONS, le navigateur bloquait → 'Failed to fetch' - Curl fonctionnait car pas de preflight
This commit is contained in:
+4
-2
@@ -11,6 +11,7 @@ use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashSet;
|
||||
use tokio::sync::Mutex;
|
||||
use tower_http::cors::CorsLayer;
|
||||
use crate::imago_client::ImagoClient;
|
||||
use crate::config::Config;
|
||||
|
||||
@@ -54,11 +55,12 @@ pub async fn serve_with_config(host: &str, port: u16, config: &Config) -> anyhow
|
||||
in_flight: Mutex::new(HashSet::new()),
|
||||
};
|
||||
|
||||
// Router principal
|
||||
// Router principal — avec CORS permissif pour les requêtes cross-origin et preflight
|
||||
let app = Router::new()
|
||||
.merge(routes::api_routes(state))
|
||||
.route("/ws", axum::routing::get(ws::ws_handler).with_state(ws_hub))
|
||||
.fallback(serve_static);
|
||||
.fallback(serve_static)
|
||||
.layer(CorsLayer::permissive());
|
||||
|
||||
let addr: SocketAddr = format!("{}:{}", host, port).parse()?;
|
||||
tracing::info!("Dashboard web démarré sur http://{}", addr);
|
||||
|
||||
Reference in New Issue
Block a user