Add CORS support

Cross-Origin requests were already implicitly allowed, but this
commit allows them explicitly and prohibits request methods other
than GET.
This commit is contained in:
Daniel Sockwell 2019-07-04 14:00:35 -04:00
parent 1765dc39ee
commit f3b86ddac8
1 changed files with 5 additions and 1 deletions

View File

@ -171,5 +171,9 @@ fn main() {
.unwrap_or("127.0.0.1:4000".to_owned())
.parse()
.expect("static string");
warp::serve(websocket.or(routes)).run(address);
let cors = warp::cors()
.allow_any_origin()
.allow_methods(vec!["GET", "OPTIONS"])
.allow_headers(vec!["Authorization", "Accept", "Cache-Control"]);
warp::serve(websocket.or(routes).with(cors)).run(address);
}