Skip to content

Navigation Menu

Sign in
Sign up

CorsLayer dont' work #10

Discussion options

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?

You must be logged in to vote
Admin verified this answer by Tuntii Jan 10, 2026

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

Comment options

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

You must be logged in to vote
3 replies
Comment options

Hello Tunay.

Thank you for your help, even though you have more important things to do right now.
I will look at #12

Comment options

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.

Answer verified by Admin Jan 10, 2026
Comment options

Hello Tunay.

Works great, thanks again. Have a nice weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working

AltStyle によって変換されたページ (->オリジナル) /