Skip to content

Commit 6f1dea3

Browse files
committed
chore: add cors on all endpoints
1 parent cadb766 commit 6f1dea3

File tree

7 files changed

+13
-3
lines changed

7 files changed

+13
-3
lines changed

api/src/guilds/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use http::StatusCode;
66
use lambda_http::tracing::warn;
77
use serde_json::{Value, json};
88
use std::sync::Arc;
9+
use tower_http::cors::CorsLayer;
910
use twilight_model::id::Id;
1011
use twilight_model::id::marker::GuildMarker;
1112

@@ -18,6 +19,7 @@ pub fn router() -> Router<AppState> {
1819
.route("/", get(get_guilds))
1920
.route("/{guild_id}", get(get_guilds_id))
2021
.nest("/{guild_id}/verify", verify::router())
22+
.layer(CorsLayer::permissive())
2123
}
2224

2325
async fn get_guilds(

api/src/guilds/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use http::StatusCode;
2-
use lambda_http::tracing::{error, info};
2+
use lambda_http::tracing::error;
33
use twilight_http::Error;
44
use twilight_model::guild::Permissions;
55
use twilight_model::id::Id;

api/src/guilds/verify.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use crate::AppState;
22
use axum::Json;
33
use axum::routing::get;
44
use serde_json::{Value, json};
5+
use tower_http::cors::CorsLayer;
56

67
pub fn router() -> axum::Router<AppState> {
78
axum::Router::new().route("/", get(get_verify))
9+
.layer(CorsLayer::permissive())
810
}
911

1012
async fn get_verify() -> Json<Value> {

api/src/interactions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use http_body_util::BodyExt;
1111
use lambda_http::tracing::error;
1212
use once_cell::sync::Lazy;
1313
use serde_json::{Value, json};
14+
use tower_http::cors::CorsLayer;
1415
use twilight_model::application::command::CommandType;
1516
use twilight_model::application::interaction::{
1617
Interaction, InteractionContextType, InteractionData, InteractionType,
@@ -38,6 +39,7 @@ pub fn router() -> axum::Router<AppState> {
3839
.route_layer(middleware::from_fn(pubkey_middleware))
3940
.route_layer(middleware::from_fn(user_agent_response_middleware))
4041
.route("/register", post(register_commands))
42+
.layer(CorsLayer::permissive())
4143
}
4244

4345
pub async fn pubkey_middleware(request: Request, next: Next) -> Result<Response, StatusCode> {

api/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ async fn main() -> Result<(), Error> {
7272
let app = Router::new()
7373
.nest("/users", users::router())
7474
.nest("/guilds", guilds::router())
75-
.layer(CorsLayer::permissive())
7675
.route_layer(axum::middleware::from_fn(middleware::auth_middleware))
7776
.nest("/interactions", interactions::router())
7877
.route_layer(axum::middleware::from_fn(middleware::log_middleware))
7978
.with_state(app_state)
8079
.route("/health", get(health_check))
81-
.route("/bot", get(get_bot_redirect));
80+
.route("/bot", get(get_bot_redirect))
81+
.layer(CorsLayer::permissive());
8282

8383
run(app).await
8484
}

api/src/users/links.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ use lambda_http::tracing::info;
77
use serde::{Deserialize, Serialize};
88
use serde_json::json;
99
use std::sync::Arc;
10+
use tower_http::cors::CorsLayer;
1011
use twilight_model::id::Id;
1112
use twilight_model::id::marker::UserMarker;
1213

1314
pub fn router() -> axum::Router<AppState> {
1415
axum::Router::new()
1516
.route("/", post(post_link))
1617
.route("/{link_address}", delete(delete_link))
18+
.layer(CorsLayer::permissive())
1719
}
1820

1921
#[derive(Clone, Serialize, Deserialize)]

api/src/users/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use http::StatusCode;
1010
use serde::Deserialize;
1111
use serde_json::{Value, json};
1212
use std::sync::Arc;
13+
use tower_http::cors::CorsLayer;
1314
use twilight_http::Client as DiscordClient;
1415
use twilight_model::id::Id;
1516
use twilight_model::id::marker::UserMarker;
@@ -19,6 +20,7 @@ pub fn router() -> axum::Router<AppState> {
1920
.route("/", get(get_users))
2021
.route("/{user_id}", get(get_users_id).put(put_users_id))
2122
.nest("/{user_id}/links", links::router())
23+
.layer(CorsLayer::permissive())
2224
}
2325

2426
async fn get_users() -> Json<Value> {

0 commit comments

Comments
 (0)