From 99a158a7dff0d84e81291d4b673dbb7d0b791517 Mon Sep 17 00:00:00 2001 From: monsterkrampe Date: Wed, 31 Aug 2022 14:00:48 +0200 Subject: [PATCH] Introduce features flag for localhost cors support --- server/Cargo.toml | 3 +++ server/src/main.rs | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/Cargo.toml b/server/Cargo.toml index 2ad8642..ddedc58 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -19,3 +19,6 @@ env_logger = "0.9" log = "0.4" serde = "1" +[features] +cors_for_local_development = [] + diff --git a/server/src/main.rs b/server/src/main.rs index f35d3e5..3012fc4 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,8 +1,10 @@ -use actix_cors::Cors; use actix_web::{get, http, post, web, App, HttpResponse, HttpServer, Responder}; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; +#[cfg(feature = "cors_for_local_development")] +use actix_cors::Cors; + use adf_bdd::adf::Adf; use adf_bdd::datatypes::BddNode; use adf_bdd::datatypes::Var; @@ -156,7 +158,8 @@ async fn main() -> std::io::Result<()> { .filter_level(log::LevelFilter::Debug) .init(); - HttpServer::new(|| { + #[cfg(feature = "cors_for_local_development")] + let server = HttpServer::new(|| { let cors = Cors::default() .allowed_origin("http://localhost:1234") .allowed_methods(vec!["GET", "POST"]) @@ -171,5 +174,13 @@ async fn main() -> std::io::Result<()> { }) .bind(("127.0.0.1", 8080))? .run() - .await + .await; + + #[cfg(not(feature = "cors_for_local_development"))] + let server = HttpServer::new(|| App::new().service(root).service(solve)) + .bind(("127.0.0.1", 8080))? + .run() + .await; + + server }