Skip to content

Commit

Permalink
feat: Added cors middleware (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Kolstad authored Jan 24, 2023
1 parent e6bc817 commit 3addbd6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/Unleash/unleash-edge"
homepage = "https://github.com/Unleash/unleash-edge"

[dependencies]
actix-cors = "0.6.4"
actix-tls = { version = "3.0.3", features = ["rustls"] }
actix-web = { version = "4.3.0", features = ["rustls"] }
actix-web-opentelemetry = { version = "0.13.0", features = ["metrics", "metrics-prometheus"] }
Expand Down
10 changes: 9 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::sync::Arc;

use crate::cli::EdgeMode;
use crate::offline_provider::OfflineProvider;
use actix_web::{middleware, web, App, HttpServer};
use actix_cors::Cors;
use actix_web::{http, middleware, web, App, HttpServer};
use actix_web_opentelemetry::RequestTracing;
use clap::Parser;
use cli::CliArgs;
Expand Down Expand Up @@ -34,8 +35,15 @@ async fn main() -> Result<(), anyhow::Error> {
let server = HttpServer::new(move || {
let client_provider_arc: Arc<dyn EdgeProvider> = Arc::new(client_provider.clone());
let client_provider_data = web::Data::from(client_provider_arc);

let cors_middleware = Cors::default()
.allowed_origin("*")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
.allowed_header(http::header::CONTENT_TYPE);
App::new()
.app_data(client_provider_data)
.wrap(cors_middleware)
.wrap(RequestTracing::new())
.wrap(request_metrics.clone())
.wrap(middleware::Logger::default())
Expand Down

0 comments on commit 3addbd6

Please sign in to comment.