Skip to content

Commit

Permalink
patch: Fix cors
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinrouillard committed May 24, 2024
1 parent ffbfe69 commit 0a98036
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ once_cell = "1.19.0"
sha1 = "0.10.6"
hex = "0.4.3"
gql_client = "1.0.7"
actix-cors = "0.7.0"

[profile.release]
lto = true
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod structs;

use std::{error::Error, time::Duration};

use actix_cors::Cors;
use actix_multipart::form::MultipartFormConfig;
use actix_web::{middleware, web, App, HttpServer};
use connectivity::{
Expand Down Expand Up @@ -79,13 +80,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

HttpServer::new(move || {
let cors = Cors::default()
.allowed_origin_fn(|origin, _req_head| {
origin.as_bytes().ends_with(b".dstn.to")
})
.allowed_origin_fn(|origin, _req_head| {
origin.as_bytes().ends_with(b":3000")
});

App::new()
.app_data(web::Data::clone(&data_http))
.app_data(
MultipartFormConfig::default()
.total_limit(10 * 1024 * 1024)
.memory_limit(10 * 1024 * 1024),
)
.wrap(cors)
.wrap(middleware::NormalizePath::default())
.wrap(TracingLogger::default())
.default_service(web::to(services::base::index))
Expand Down

0 comments on commit 0a98036

Please sign in to comment.