diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-03-19 20:27:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-19 20:27:53 +0100 |
commit | 4249c2e09579d6454e7572111e44c284190a2c8f (patch) | |
tree | fc47bb02aa430accce176903af5e36b81179c87a /src/main.rs | |
parent | 9a791db0c1a8bd08cf51950ed28066adcef84bca (diff) | |
parent | 8225cba5ce69a073b54e2eeba7c9d466efa107e3 (diff) |
Merge pull request #20 from gico-net/feat/cors
Enable CORS
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 2e499f9..6ac5d2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,11 @@ mod commit; mod email; mod repository; -use actix_web::{middleware, App, HttpServer}; +use actix_cors::Cors; +use actix_web::{http::header, middleware, App, HttpServer}; use dotenv::dotenv; use slog::info; +use std::env; use tokio_postgres::NoTls; use crate::config::{AppState, Config}; @@ -39,6 +41,21 @@ async fn main() -> std::io::Result<()> { log: log.clone(), }) .wrap(middleware::Logger::default()) + .wrap( + Cors::default() + .allowed_origin( + &env::var("CLIENT") + .unwrap_or("http://localhost:8080".to_string())[..] + ) + .allowed_methods(vec!["GET", "POST", "DELETE"]) + .allowed_headers(vec![ + header::AUTHORIZATION, + header::ACCEPT, + ]) + .allowed_header(header::CONTENT_TYPE) + .supports_credentials() + .max_age(3600), + ) .configure(repository::routes::config) .configure(email::routes::config) .configure(commit::routes::config) |