Add cors open

This commit is contained in:
Romulus21
2025-12-26 15:40:14 +01:00
parent 3663562b8a
commit 3f1eb33d6a
2 changed files with 7 additions and 1 deletions

View File

@@ -11,7 +11,7 @@ axum = { version = "0.7", optional = true }
jsonwebtoken = { version = "9", optional = true } jsonwebtoken = { version = "9", optional = true }
tokio = { version = "1.39", features = ["rt-multi-thread"], optional = true } tokio = { version = "1.39", features = ["rt-multi-thread"], optional = true }
tower = { version = "0.4", optional = true } tower = { version = "0.4", optional = true }
tower-http = { version = "0.5", features = ["fs", "trace"], optional = true } tower-http = { version = "0.5", features = ["fs", "trace", "cors"], optional = true }
sqlx = { version = "0.8", features = [ sqlx = { version = "0.8", features = [
"runtime-tokio-rustls", "runtime-tokio-rustls",
"sqlite", "sqlite",

View File

@@ -21,10 +21,16 @@ pub async fn init_app(configuration_path: Option<&str>) {
let leptos_options = conf.leptos_options; let leptos_options = conf.leptos_options;
let serve_dir = tower_http::services::ServeDir::new(&leptos_options.site_root) let serve_dir = tower_http::services::ServeDir::new(&leptos_options.site_root)
.append_index_html_on_directories(false); .append_index_html_on_directories(false);
let cors = tower_http::cors::CorsLayer::new()
.allow_methods([axum::http::Method::GET, axum::http::Method::POST])
.allow_origin(tower_http::cors::Any);
logging::log!("listening on http://{}", &addr); logging::log!("listening on http://{}", &addr);
let app = axum::Router::new() let app = axum::Router::new()
.leptos_routes(&leptos_options, routes, || view! { <App/> }) .leptos_routes(&leptos_options, routes, || view! { <App/> })
.fallback_service(serve_dir) .fallback_service(serve_dir)
.layer(cors)
.layer( .layer(
tower_http::trace::TraceLayer::new_for_http() tower_http::trace::TraceLayer::new_for_http()
.make_span_with( .make_span_with(