1
0
mirror of https://github.com/ellmau/adf-obdd.git synced 2025-12-20 09:39:38 +01:00

Introduce features flag for localhost cors support

This commit is contained in:
monsterkrampe 2022-08-31 14:00:48 +02:00
parent e5df39206c
commit 393ee39f0c
No known key found for this signature in database
GPG Key ID: B8ADC1F5A5CE5057
2 changed files with 17 additions and 3 deletions

View File

@ -19,3 +19,6 @@ env_logger = "0.9"
log = "0.4"
serde = "1"
[features]
cors_for_local_development = []

View File

@ -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
}