Skip to content

Files

Latest commit

e63086a · Jul 15, 2019

History

History
This branch is 913 commits behind http-rs/tide:main.

tide-cors

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 15, 2019
Jul 4, 2019
Jul 15, 2019

README.md

tide-cors

This crate provides cors-related middleware for Tide.

Examples

Examples are in the /examples folder of this crate.

#![feature(async_await)]

use http::header::HeaderValue;
use tide::middleware::CorsMiddleware;

fn main() {
    let mut app = tide::App::new();

    app.middleware(
        CorsMiddleware::new()
            .allow_origin(HeaderValue::from_static("*"))
            .allow_methods(HeaderValue::from_static("GET, POST, OPTIONS")),
    );

    app.at("/").get(|_| async move { "Hello, world!" });

    app.run("127.0.0.1:8000").unwrap();
}

Simple Example

You can test the simple example by running cargo run --example cors while in this crate's directory, and then running this script in the browser console:

$ fetch("http://127.0.0.1:8000")

You will probably get a browser alert when running without cors middleware.