Add CORS
This commit is contained in:
parent
f26457c2cf
commit
69babdf5a3
2 changed files with 9 additions and 0 deletions
|
|
@ -23,3 +23,4 @@ aide = { version = "0.13.4", features = ["axum", "axum-ws", "scalar", "axum-head
|
|||
schemars = { version = "0.8.21", features = ["chrono", "uuid1"] }
|
||||
rand = "0.8.5"
|
||||
axum-extra = { version = "0.9.6", features = ["typed-header"] }
|
||||
tower-http = { version = "0.6.1", features = ["cors"] }
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ use aide::{
|
|||
use anyhow::{Context, Result};
|
||||
use axum::{
|
||||
extract::{DefaultBodyLimit, WebSocketUpgrade},
|
||||
http::{self, HeaderValue, Method},
|
||||
response::{IntoResponse, Response},
|
||||
Extension, Json,
|
||||
};
|
||||
use log::info;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
use crate::app_state::AppState;
|
||||
mod auth;
|
||||
|
|
@ -64,6 +66,12 @@ pub async fn create_server(app_state: AppState) -> Result<()> {
|
|||
.layer(DefaultBodyLimit::max(
|
||||
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)
|
||||
.finish_api(&mut api)
|
||||
.layer(Extension(api))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue