Skip to content

Commit

Permalink
Bump axum & allow for requests without an application/json header (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony1060 authored Feb 11, 2024
1 parent 4fcdc30 commit c343a62
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 50 deletions.
153 changes: 120 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.1"
edition = "2021"

[dependencies]
axum = "0.6.20"
axum = "0.7.4"
chrono = "0.4.31"
dotenvy = "0.15.7"
ethers = "2.0.10"
Expand All @@ -19,10 +19,11 @@ serde_json = "1.0.108"
thiserror = "1.0.50"
tokio = {version = "1", features = ["full"]}
tokio-postgres = "0.7.10"
tower-http = { version = "0.4.4", features = ["cors"] }
tower-http = { version = "0.5.1", features = ["cors"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"]}
lazy_static = { version = "1.4.0", features = [] }
bytes = "1.5.0"

# Multicoin encoding
bs58 = "0.5.0"
Expand Down
7 changes: 4 additions & 3 deletions src/gateway/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ use std::sync::Arc;
use axum::{
extract::State,
response::{IntoResponse, Response},
Json,
};
use thiserror::Error;

use crate::state::GlobalState;
use crate::utils;

use super::{payload::ResolveCCIPPostPayload, response::GatewayResponse};

pub async fn route(
// Ommiting sender from path awaiting viem patch
// Omitting sender from path awaiting viem patch
// Path(sender): Path<String>,
State(state): State<Arc<GlobalState>>,
Json(request_payload): Json<ResolveCCIPPostPayload>,
// custom less strict json implementation because viem makes the request wrong
utils::axum_json::Json(request_payload): utils::axum_json::Json<ResolveCCIPPostPayload>,
) -> impl IntoResponse {
handle(request_payload, state)
.await
Expand Down
25 changes: 13 additions & 12 deletions src/http.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{env, net::SocketAddr, sync::Arc};
use std::{env, sync::Arc};

use axum::{
routing::{get, post},
Router, Server,
Router,
};
use tokio::net::TcpListener;
use tower_http::cors::CorsLayer;
use tracing::{debug, info};

Expand All @@ -25,19 +26,19 @@ pub async fn serve(state: GlobalState) {
.with_state(Arc::new(state))
.layer(CorsLayer::very_permissive());

let addr = SocketAddr::from((
[0, 0, 0, 0],
let listener = TcpListener::bind(format!(
"0.0.0.0:{}",
env::var("PORT")
.unwrap_or("3000".to_string())
.parse::<u16>()
.expect("port should fit in u16"),
));
debug!("Listening on {}", addr);

Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
.expect("port should fit in u16")
))
.await
.unwrap();

debug!("Listening on {}", listener.local_addr().unwrap());

axum::serve(listener, app).await.unwrap();
}

/// Self Endpoint on the Gateway
Expand Down
Loading

0 comments on commit c343a62

Please sign in to comment.