Function routerify_cors::enable_cors_all[][src]

pub fn enable_cors_all<B, E>() -> Middleware<B, E> where
    B: HttpBody + Send + Sync + Unpin + 'static,
    E: Error + Send + Sync + Unpin + 'static, 
Expand description

Enables CORS for all routes.

Examples

use hyper::{Body, Request, Response, Server};
use routerify::{Router, RouterService};
// Import the CORS crate.
use routerify_cors::enable_cors_all;
use std::{convert::Infallible, net::SocketAddr};

// A handler for "/" page.
async fn home_handler(_: Request<Body>) -> Result<Response<Body>, Infallible> {
    Ok(Response::new(Body::from("Home page")))
}

// Create a router.
Router::builder()
  // Attach the CORS middleware.
  .middleware(enable_cors_all())
  .get("/", home_handler)
  .build()
  .unwrap()