Skip to content

Commit

Permalink
fix: use permissive cors like actix
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-micah committed Feb 29, 2024
1 parent a1fbbe8 commit d7cb4ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/routes/bigcommerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum InstallError {
}

impl IntoResponse for InstallError {
fn into_response(self) -> axum::response::Response {
fn into_response(self) -> Response {
match self {
Self::UnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
}
Expand Down
9 changes: 5 additions & 4 deletions apps/server/src/routes/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use tower_http::cors::{Any, CorsLayer};
use anyhow::Context;
use axum::{
extract::{Query, State},
http::{Method, StatusCode},
http::{
header::{ACCEPT, AUTHORIZATION},

Check failure on line 19 in apps/server/src/routes/widget.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `ACCEPT`, `AUTHORIZATION`, `Method`

error: unused imports: `ACCEPT`, `AUTHORIZATION`, `Method` --> apps/server/src/routes/widget.rs:19:18 | 19 | header::{ACCEPT, AUTHORIZATION}, | ^^^^^^ ^^^^^^^^^^^^^ 20 | Method, StatusCode, | ^^^^^^
Method, StatusCode,
},
response::{IntoResponse, Response},
routing::{delete, get, post},
Json, Router,
Expand All @@ -30,9 +33,7 @@ pub fn router() -> Router<SharedState> {
.route("/publish", delete(remove_widget))
.route("/preview", get(preview_widget));

let cors = CorsLayer::new()
.allow_methods([Method::GET, Method::POST])
.allow_origin(Any);
let cors = CorsLayer::permissive();

let v2_router = Router::new()
.layer(cors)
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Application {
.local_addr()
.expect("listener does not have an address")
.port();
let server = run(listener, configuration.get_app_state());
let server = build_server(listener, configuration.get_app_state());

Ok(Self { port, server })
}
Expand All @@ -52,7 +52,7 @@ pub fn get_connection_pool(configuration: &Database) -> PgPool {

#[allow(clippy::default_constructed_unit_structs)]
// reason = "`OtelInResponseLayer` struct is an external dependency that might change"
pub fn run(listener: TcpListener, shared_state: SharedState) -> Serve<Router, Router> {
pub fn build_server(listener: TcpListener, shared_state: SharedState) -> Serve<Router, Router> {
let app = Router::new()
.merge(routes::router())
.layer(OtelInResponseLayer::default())
Expand Down

0 comments on commit d7cb4ef

Please sign in to comment.