Skip to content

Commit ffee532

Browse files
committed
Add CORS test example project
Introduces a new example 'cors-test' to demonstrate CORS, rate limiting, and middleware usage with rustapi-rs. Updates workspace members in Cargo.toml and bumps rustapi-related crate versions to 0.1.8.
1 parent 5274871 commit ffee532

4 files changed

Lines changed: 55 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 22 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ members = [
2424
# "examples/graphql-api", # TODO: Needs API updates
2525
"examples/microservices",
2626
"examples/middleware-chain",
27+
"examples/cors-test",
2728
"benches/toon_bench",
2829
]
2930

examples/cors-test/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "cors-test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rustapi-rs = { path = "../../crates/rustapi-rs", features = ["cors", "rate-limit"] }
8+
rustapi-macros = { path = "../../crates/rustapi-macros" }
9+
tokio = { version = "1", features = ["full"] }
10+
serde = { version = "1", features = ["derive"] }
11+
serde_json = "1"

examples/cors-test/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use rustapi_rs::prelude::*;
2+
use std::time::Duration;
3+
4+
async fn hello() -> &'static str {
5+
"Hello from CORS-enabled API!"
6+
}
7+
8+
#[tokio::main]
9+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
10+
println!("🚀 Testing CorsLayer with the exact user configuration...");
11+
println!("✅ If this compiles, CorsLayer works!");
12+
13+
RustApi::new()
14+
.route("/", get(hello))
15+
.layer(CorsLayer::permissive())
16+
.layer(RequestIdLayer::new())
17+
.layer(TracingLayer::new())
18+
.layer(RateLimitLayer::new(100, Duration::from_secs(60)))
19+
.run("127.0.0.1:3030")
20+
.await
21+
}

0 commit comments

Comments
 (0)