CorsLayer dont' work #10
Verified answer
by
Tuntii
PeterGumball
asked this question in
Error and Bugs
-
|
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
Can you help? |
Beta Was this translation helpful? Give feedback.
Admin verified this answer by
Tuntii
Jan 10, 2026
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 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.