feat: added cors for web-player-backend

This commit is contained in:
Boris Cherepanov
2026-03-23 12:34:27 +03:00
parent f26135ca25
commit 310f0061d3
10 changed files with 323 additions and 39 deletions

View File

@@ -25,3 +25,4 @@ base64 = "0.22"
rand = "0.8"
urlencoding = "2.1.3"
rustls = { version = "0.23", features = ["ring"] }
tower-http = { version = "0.6", features = ["cors"] }

View File

@@ -3,9 +3,12 @@ pub mod auth;
use std::sync::Arc;
use std::path::PathBuf;
use std::time::Duration;
use axum::{Router, routing::get, middleware};
use axum::http::{header, Method};
use sqlx::PgPool;
use tower_http::cors::{Any, CorsLayer};
#[derive(Clone)]
pub struct AppState {
@@ -42,12 +45,19 @@ pub fn build_router(state: Arc<AppState>) -> Router {
authed
};
let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods([Method::GET, Method::OPTIONS, Method::HEAD])
.allow_headers([header::ACCEPT, header::CONTENT_TYPE, header::HeaderName::from_static("x-api-key")])
.max_age(Duration::from_secs(600));
Router::new()
.route("/login", get(auth::login_page))
.route("/logout", get(auth::logout))
.route("/auth/login", get(auth::oidc_login))
.route("/auth/callback", get(auth::oidc_callback))
.merge(app)
.layer(cors)
.with_state(state)
}