-
-
Notifications
You must be signed in to change notification settings - Fork 4
CorsLayer dont' work #10
Hello.
Can you give me an example how to use the CorsLayer? Can't get it to work.
My Cargo.toml
async-trait = "0.1.89" chrono = { version = "0.4", features = ["serde"] } rustapi-rs = { version = "0.1.7", features = ["rate-limit", "config", "sqlx", "cors"] } serde = { version = "1", features = ["derive"] } sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "postgres", "uuid", "chrono"] } tokio = { version = "1", features = ["full"] } utoipa = { version = "4.2" } uuid = { version = "1", features = ["v4", "serde"] } validator = { version = "0.18", features = ["derive"] }
My main.rs
mod config; mod db_utils; mod features; mod models; mod state; use std::{time::Duration}; use rustapi_rs::prelude::*; use crate::{config::AppConfig, state::AppState}; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { // Load .env file at startup load_dotenv(); // Load config from environment variables let config = Config::<AppConfig>::from_env().expect("Failed to load config"); // Create app state let app_state = AppState::new(&config.database_url) .await .expect("Failed to create app state"); // Run application RustApi::auto() .state(app_state) .layer(CorsLayer::permissive()) .layer(RequestIdLayer::new()) .layer(TracingLayer::new()) .layer(RateLimitLayer::new(100, Duration::from_secs(60))) .run(&config.server_address).await }
At the line with .layer(CorsLayer::permissive()) i get following error:
the trait bound rustapi_rs::CorsLayer: MiddlewareLayer is not satisfied
Can you help?
All reactions
-
👀 1
Hello Peter
I've pushed the PR containing the update to the main repo and updated the crates.
Please update to the current version and try again.
Replies: 1 comment 3 replies
Hello!, I'm not at my computer right now due to health issues with a family member. I'm aware of the problem. You can check it out here. Thanks for your contribution! #12
All reactions
Hello Tunay.
Thank you for your help, even though you have more important things to do right now.
I will look at #12
All reactions
Hello Peter
I've pushed the PR containing the update to the main repo and updated the crates.
Please update to the current version and try again.
All reactions
-
👍 1
Hello Tunay.
Works great, thanks again. Have a nice weekend.
All reactions
-
❤️ 1 -
🚀 1