Skip to content

Commit b7445c7

Browse files
committed
FEAT: Cors
1 parent 2f80884 commit b7445c7

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ actix-web = "4.9.0"
88
bollard = "0.18.1"
99
tokio = { version = "1.43.0", features = ["full"] }
1010
serde = { version = "1.0.217", features = ["derive"] }
11-
serde_json = "1.0.138"
11+
serde_json = "1.0.138"
12+
actix-cors = "0.7.0"

src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use actix_cors::Cors;
34
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
45
use bollard::Docker;
56

@@ -17,6 +18,15 @@ async fn main() -> std::io::Result<()> {
1718

1819
HttpServer::new(move || {
1920
App::new()
21+
.wrap(Cors::default()
22+
.allow_any_origin()
23+
.allow_any_method()
24+
.allow_any_header()
25+
.max_age(3600)
26+
.send_wildcard())
27+
.wrap(actix_web::middleware::Logger::default())
28+
.wrap(actix_web::middleware::NormalizePath::default())
29+
.wrap(actix_web::middleware::Compress::default())
2030
.app_data(web::Data::new(docker.clone()))
2131
.route("/containers", web::get().to(list_containers))
2232
})

0 commit comments

Comments
 (0)