From 017cf9e464cc5ab1aea8a0fdffd7e16b99df11d4 Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Thu, 27 Aug 2020 08:47:18 -0700 Subject: [PATCH] Make CORS work (#52) * Make CORS work * Add use statement * Add to TOML --- Cargo.toml | 1 + src/main.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 947f805ca..e0f938b6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ actix-web = "2.0" actix-rt = "1.1.1" actix-files = "0.2.2" actix-multipart = "0.2.0" +actix-cors = "0.2.0" reqwest = {version="0.10.6", features=["json"]} diff --git a/src/main.rs b/src/main.rs index 7e53d5dba..876d3936f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use actix_web::middleware::Logger; -use actix_web::{web, App, HttpServer}; +use actix_cors::Cors; +use actix_web::{web, App, HttpServer, http}; use env_logger::Env; use gumdrop::Options; use log::{info, warn}; @@ -170,6 +171,15 @@ async fn main() -> std::io::Result<()> { // Init App HttpServer::new(move || { App::new() + .wrap( + Cors::new() + .allowed_origin("http://localhost:3000") + .allowed_methods(vec!["GET", "POST"]) + .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT]) + .allowed_header(http::header::CONTENT_TYPE) + .max_age(3600) + .finish() + ) .wrap(Logger::default()) .wrap(Logger::new("%a %{User-Agent}i")) .data(pool.clone())