64 releases (28 breaking)

new 0.66.1 Feb 28, 2024
0.65.2 Feb 2, 2024
0.63.1 Dec 21, 2023
0.59.0 Nov 30, 2023
0.37.6 Nov 29, 2022

#1264 in HTTP server

Download history 808/week @ 2023-11-07 761/week @ 2023-11-14 972/week @ 2023-11-21 943/week @ 2023-11-28 1027/week @ 2023-12-05 1050/week @ 2023-12-12 1073/week @ 2023-12-19 1217/week @ 2023-12-26 1044/week @ 2024-01-02 1373/week @ 2024-01-09 1072/week @ 2024-01-16 1071/week @ 2024-01-23 1235/week @ 2024-01-30 1055/week @ 2024-02-06 1979/week @ 2024-02-13 2741/week @ 2024-02-20

7,164 downloads per month
Used in salvo

MIT/Apache

665KB
15K SLoC

salvo-cors

Library to Provide a CORS protection for Salvo.

This is offical crate, so you can enable it in Cargo.toml like this:

salvo = { version = "*", features=["cors"] }

Docs


lib.rs:

Cross-Origin Resource Sharing (CORS) support for Savlo web server framework.

Example

use salvo_core::http::Method;
use salvo_core::prelude::*;
use salvo_cors::Cors;

let cors_handler = Cors::new()
    .allow_origin("https://salvo.rs")
    .allow_methods(vec![Method::GET, Method::POST, Method::DELETE]).into_handler();

let router = Router::new().hoop(cors_handler).post(upload_file).options(upload_file);
#[handler]
async fn upload_file(res: &mut Response) {
}

If you want to allow any router:

use salvo_core::prelude::*;
use salvo_cors::{self as cors, Cors};
let cors_handler = Cors::new().allow_origin(cors::Any).into_handler();

Read more: https://salvo.rs

Dependencies

~18–33MB
~562K SLoC