This commit is contained in:
Andras Schmelczer 2024-12-08 22:02:34 +00:00
commit 69babdf5a3
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 9 additions and 0 deletions

View file

@ -23,3 +23,4 @@ aide = { version = "0.13.4", features = ["axum", "axum-ws", "scalar", "axum-head
schemars = { version = "0.8.21", features = ["chrono", "uuid1"] } schemars = { version = "0.8.21", features = ["chrono", "uuid1"] }
rand = "0.8.5" rand = "0.8.5"
axum-extra = { version = "0.9.6", features = ["typed-header"] } axum-extra = { version = "0.9.6", features = ["typed-header"] }
tower-http = { version = "0.6.1", features = ["cors"] }

View file

@ -9,10 +9,12 @@ use aide::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use axum::{ use axum::{
extract::{DefaultBodyLimit, WebSocketUpgrade}, extract::{DefaultBodyLimit, WebSocketUpgrade},
http::{self, HeaderValue, Method},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
Extension, Json, Extension, Json,
}; };
use log::info; use log::info;
use tower_http::cors::CorsLayer;
use crate::app_state::AppState; use crate::app_state::AppState;
mod auth; mod auth;
@ -64,6 +66,12 @@ pub async fn create_server(app_state: AppState) -> Result<()> {
.layer(DefaultBodyLimit::max( .layer(DefaultBodyLimit::max(
app_state.config.server.max_body_size_mb * 1024 * 1024, app_state.config.server.max_body_size_mb * 1024 * 1024,
)) ))
.layer(
CorsLayer::new()
.allow_origin("*".parse::<HeaderValue>().unwrap())
.allow_headers([http::header::CONTENT_TYPE, http::header::AUTHORIZATION])
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE]),
)
.with_state(app_state) .with_state(app_state)
.finish_api(&mut api) .finish_api(&mut api)
.layer(Extension(api)) .layer(Extension(api))