Skip to content

Commit

Permalink
feat: enable cors (#82)
Browse files Browse the repository at this point in the history
* feat: enable cors

* fix: lint formats

* Simplify cors allow all

---------

Co-authored-by: SHAcollision <[email protected]>
  • Loading branch information
MiguelMedeiros and SHAcollision authored Aug 21, 2024
1 parent bcc03f5 commit 23c131b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ serde_json = "1.0.125"
once_cell = "1.19.0"
utoipa = "4.2.3"
utoipa-swagger-ui = { version = "7.1.0", features = ["axum"] }
tower-http = { version = "0.5.2", features = ["fs"] }
tower-http = { version = "0.5.2", features = ["fs", "cors"] }
dotenv = "0.15"
log = "0.4.22"
env_logger = "0.11.5"
Expand Down
13 changes: 12 additions & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use axum::Router;
use tower_http::cors::{Any, CorsLayer};

pub mod macros;
pub mod r#static;
Expand All @@ -8,5 +9,15 @@ pub fn routes() -> Router {
let routes_v0 = v0::routes();
let route_static = r#static::routes();

routes_v0.merge(route_static)
// Combine routes
let app = routes_v0.merge(route_static);

// Create a CORS layer that allows all origins, methods, and headers
let cors = CorsLayer::new()
.allow_origin(Any) // Allow all origins
.allow_methods(Any) // Allow all HTTP methods
.allow_headers(Any); // Allow all headers

// Layer the CORS middleware on top of the routes
app.layer(cors)
}

0 comments on commit 23c131b

Please sign in to comment.