diff --git a/Cargo.toml b/Cargo.toml index 6d3e486..9f8d10d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ axum = { version = "0.7", optional = true } jsonwebtoken = { version = "9", optional = true } tokio = { version = "1.39", features = ["rt-multi-thread"], 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 = [ "runtime-tokio-rustls", "sqlite", diff --git a/src/setup.rs b/src/setup.rs index 688be63..e74c691 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -21,10 +21,16 @@ pub async fn init_app(configuration_path: Option<&str>) { let leptos_options = conf.leptos_options; let serve_dir = tower_http::services::ServeDir::new(&leptos_options.site_root) .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); let app = axum::Router::new() .leptos_routes(&leptos_options, routes, || view! { }) .fallback_service(serve_dir) + .layer(cors) .layer( tower_http::trace::TraceLayer::new_for_http() .make_span_with(