Crate salvo_cors

Source
Expand description

Library adds CORS protection for Salvo web 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

Structs§

Enums§

  • Enum to control when to call next handler.

Functions§