Skip to content

Commit fd49176

Browse files
Merge pull request #110 from reddevilmidzy/cors
CORS 설정 추가
2 parents 7768b28 + 4b0aca4 commit fd49176

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

rook/Cargo.lock

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

rook/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ once_cell = "1.18"
2020
tracing = "0.1"
2121
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2222
futures = "0.3"
23+
tower-http = { version = "0.6", features = ["cors"] }
2324

2425
# shuttle 의존성 지우기
2526
shuttle-axum = "0.55.0"

rook/src/main.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ use queensac::{cancel_repository_checker, check_repository_links, stream_link_ch
88
use axum::{
99
Json, Router,
1010
extract::{Query, State},
11-
http::StatusCode,
11+
http::{
12+
HeaderValue, Method, StatusCode,
13+
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
14+
},
1215
routing::{delete, get, post},
1316
};
1417
use sqlx::PgPool;
1518
use std::sync::Arc;
1619
use std::time::Duration;
20+
use tower_http::cors::CorsLayer;
1721
use tracing::{Level, error, info};
1822
use tracing_subscriber::FmtSubscriber;
1923

@@ -122,8 +126,7 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut
122126
.pretty()
123127
.init();
124128

125-
info!("Starting Queensac service...");
126-
129+
info!("Starting queensac service...");
127130
dotenvy::dotenv().ok();
128131

129132
// 이메일 클라이언트 설정 로드
@@ -154,11 +157,21 @@ async fn main(#[shuttle_shared_db::Postgres] pool: PgPool) -> shuttle_axum::Shut
154157
}
155158

156159
fn app(pool: PgPool, email_client: Arc<EmailClient>) -> Router {
160+
let cors = CorsLayer::new()
161+
.allow_origin([
162+
HeaderValue::from_static("https://redddy.com"),
163+
HeaderValue::from_static("https://www.redddy.com"),
164+
])
165+
.allow_methods([Method::GET, Method::POST, Method::DELETE, Method::OPTIONS])
166+
.allow_headers([CONTENT_TYPE, AUTHORIZATION, ACCEPT])
167+
.allow_credentials(true);
168+
157169
Router::new()
158170
.route("/", get(|| async { "Sacrifice the Queen!!" }))
159171
.route("/health", get(health_check))
160172
.route("/check", post(check_handler))
161173
.route("/check", delete(cancel_handler))
162174
.route("/stream", get(stream_handler))
163175
.with_state((pool, email_client))
176+
.layer(cors)
164177
}

0 commit comments

Comments
 (0)