Skip to content

Commit

Permalink
Add cors
Browse files Browse the repository at this point in the history
  • Loading branch information
gueldenstone committed May 12, 2024
1 parent 14cbbea commit 54d6026
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
config = "0.14.0"
actix-web = "^4"
actix-cors = "0.7"
serde = { version = "^1", features = ["derive"] }
spaceapi = "^0.9"
log = "^0.4"
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ mod api;
mod errors;
mod settings;

use actix_web::{middleware::Logger, web::Data, App, HttpServer};
use actix_cors::Cors;
use actix_web::{http, middleware::Logger, web::Data, App, HttpServer};
use spaceapi::Status;
use std::sync::Mutex;

Expand All @@ -29,8 +30,14 @@ async fn main() -> std::io::Result<()> {
});
HttpServer::new(move || {
let logger = Logger::default();
let cors = Cors::default()
.allow_any_origin()
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
.allowed_header(http::header::CONTENT_TYPE);
App::new()
.wrap(logger)
.wrap(cors)
.service(api::get_status)
.service(api::set_state)
.app_data(app_state_data.clone())
Expand Down

0 comments on commit 54d6026

Please sign in to comment.