Skip to content

Commit

Permalink
Deepbook Indexer CORS Update (#20987)
Browse files Browse the repository at this point in the history
## Description 

CORS Update to allow cross origin requests

## Test plan 

How did you test the new or updated feature?

Tested locally using a local server calling the endpoint from a
different origin

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
tonylee08 authored Jan 27, 2025
1 parent 9c4b3e2 commit 0c2102e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 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 crates/sui-deepbook-indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sui-config.workspace = true
sui-indexer-builder.workspace = true
tempfile.workspace = true
axum.workspace = true
tower-http.workspace = true
bigdecimal = { version = "0.4.5" }
serde_json = { version = "1.0", features = ["preserve_order"] }

Expand Down
8 changes: 8 additions & 0 deletions crates/sui-deepbook-indexer/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
schema::{self},
sui_deepbook_indexer::PgDeepbookPersistent,
};
use axum::http::Method;
use axum::{
extract::{Path, Query, State},
http::StatusCode,
Expand All @@ -22,6 +23,7 @@ use serde_json::Value;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{collections::HashMap, net::SocketAddr};
use tokio::{net::TcpListener, task::JoinHandle};
use tower_http::cors::{AllowMethods, Any, CorsLayer};

use std::str::FromStr;
use sui_json_rpc_types::{SuiObjectData, SuiObjectDataOptions, SuiObjectResponse};
Expand Down Expand Up @@ -69,6 +71,11 @@ pub fn run_server(socket_address: SocketAddr, state: PgDeepbookPersistent) -> Jo
}

pub(crate) fn make_router(state: PgDeepbookPersistent) -> Router {
let cors = CorsLayer::new()
.allow_methods(AllowMethods::list(vec![Method::GET, Method::OPTIONS]))
.allow_headers(Any)
.allow_origin(Any);

Router::new()
.route("/", get(health_check))
.route(GET_POOLS_PATH, get(get_pools))
Expand All @@ -90,6 +97,7 @@ pub(crate) fn make_router(state: PgDeepbookPersistent) -> Router {
.route(ASSETS_PATH, get(assets))
.route(SUMMARY_PATH, get(summary))
.route(DEEP_SUPPLY_PATH, get(deep_supply))
.layer(cors)
.with_state(state)
}

Expand Down

0 comments on commit 0c2102e

Please sign in to comment.