Skip to content

Commit 0a98036

Browse files
committedMay 24, 2024··
patch: Fix cors
1 parent ffbfe69 commit 0a98036

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
 

‎Cargo.lock

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ once_cell = "1.19.0"
3434
sha1 = "0.10.6"
3535
hex = "0.4.3"
3636
gql_client = "1.0.7"
37+
actix-cors = "0.7.0"
3738

3839
[profile.release]
3940
lto = true

‎src/main.rs

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod structs;
66

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

9+
use actix_cors::Cors;
910
use actix_multipart::form::MultipartFormConfig;
1011
use actix_web::{middleware, web, App, HttpServer};
1112
use connectivity::{
@@ -79,13 +80,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
7980
}
8081

8182
HttpServer::new(move || {
83+
let cors = Cors::default()
84+
.allowed_origin_fn(|origin, _req_head| {
85+
origin.as_bytes().ends_with(b".dstn.to")
86+
})
87+
.allowed_origin_fn(|origin, _req_head| {
88+
origin.as_bytes().ends_with(b":3000")
89+
});
90+
8291
App::new()
8392
.app_data(web::Data::clone(&data_http))
8493
.app_data(
8594
MultipartFormConfig::default()
8695
.total_limit(10 * 1024 * 1024)
8796
.memory_limit(10 * 1024 * 1024),
8897
)
98+
.wrap(cors)
8999
.wrap(middleware::NormalizePath::default())
90100
.wrap(TracingLogger::default())
91101
.default_service(web::to(services::base::index))

0 commit comments

Comments
 (0)
Please sign in to comment.