Skip to content

Commit

Permalink
cors設定をした
Browse files Browse the repository at this point in the history
全てからのアクセスを許可
  • Loading branch information
puripuri2100 committed Sep 20, 2023
1 parent 8a08bf7 commit f92f21f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
25 changes: 25 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 @@ -17,6 +17,7 @@ sqlx = { version = "0.7.0", features = [ "runtime-tokio-rustls", "json", "chrono
structopt = "0.3.26"
thiserror = "1.0.41"
tokio = { version = "1.29.1", features = ["full"] }
tower-http = { version = "0.4.4", features = ["cors"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
url = "2.4.0"
Expand Down
7 changes: 7 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use anyhow::Result;
use axum::{
extract::Query,
http::Method,
routing::{delete, get, post},
Router,
};
use chrono::Utc;
use std::collections::HashMap;
use std::net::SocketAddr;
use std::sync::Arc;
use tower_http::cors::{Any, CorsLayer};
use uuid::Uuid;

/// コンテナの管理を行うエンドポイントの定義
Expand Down Expand Up @@ -138,6 +140,11 @@ pub async fn app(bind: SocketAddr) -> Result<()> {
let conn = Arc::clone(&conn);
move |body| container::insert_container(body, conn)
}),
)
.layer(
CorsLayer::new()
.allow_methods([Method::GET, Method::POST])
.allow_origin(Any),
);

// サーバーの実行
Expand Down

0 comments on commit f92f21f

Please sign in to comment.