use std::sync::Arc;
use axum::{Json, Router, extract::State, http::Method, routing::get};
use pib_service_api_types::config::api::ApiConfig;
use tower_http::cors::{Any, CorsLayer};
use crate::ServiceState;
pub(super) fn router(service_state: ServiceState) -> Router {
let cors = CorsLayer::new()
.allow_methods([
Method::GET,
Method::POST,
Method::PUT,
Method::DELETE,
Method::PATCH,
])
.allow_origin(Any);
Router::new()
.route("/config", get(config))
.layer(cors)
.with_state(Arc::new(service_state))
}
async fn config(State(service_state): State<Arc<ServiceState>>) -> Json<ApiConfig> {
Json(ApiConfig {
oidc: service_state.oidc.clone(),
})
}