Skip to content

Commit

Permalink
enable cors (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-t-wang authored Oct 16, 2024
1 parent 78aeac6 commit 3280c65
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
15 changes: 15 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 @@ -45,6 +45,7 @@ sqlx = { version = "0.8.1", features = [
"tls-rustls",
"runtime-tokio",
], default-features = false }
tower-http = { version="0.6.1", features= ["cors"]}


[build-dependencies]
Expand Down
8 changes: 8 additions & 0 deletions src/routes/api/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ mod rename;
mod update_record;

use ens_gateway::{docs as ens_gateway_docs, ens_gateway};
use http::Method;
use query_multiple::{docs as query_multiple_docs, query_multiple};
use query_single::{docs as query_single_docs, query_single};
use register_username::{docs as register_username_docs, register_username};
use rename::{docs as rename_docs, rename};
use tower_http::cors::{Any, CorsLayer};
use update_record::{docs as update_record_docs, update_record};

pub fn handler() -> ApiRouter {
let cors = CorsLayer::new()
.allow_origin(Any) // Or you can specify allowed origins
.allow_methods(vec![Method::GET, Method::POST, Method::OPTIONS]) // Allow OPTIONS method
.allow_headers(Any); // Allow any headers

ApiRouter::new()
.api_route("/ens", post_with(ens_gateway, ens_gateway_docs))
.layer(cors)
.api_route("/query", post_with(query_multiple, query_multiple_docs))
.api_route("/rename", post_with(rename, rename_docs))
.api_route(
Expand Down

0 comments on commit 3280c65

Please sign in to comment.