From 74aaec5288857bdffacfd48f3b4a29cae1658b9c Mon Sep 17 00:00:00 2001 From: Luc Date: Wed, 5 Jul 2023 02:25:47 +0000 Subject: [PATCH] Introduce CORS Headers --- Cargo.lock | 49 +++++++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 9 +++++++-- src/http.rs | 2 ++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2bd9f0a..9ca1ac2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,7 +133,7 @@ checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes", "futures-util", "http", @@ -234,6 +234,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + [[package]] name = "bitvec" version = "0.17.4" @@ -789,6 +795,7 @@ dependencies = [ "serde", "serde_json", "tokio", + "tower-http", "tracing", "utoipa", "utoipa-swagger-ui", @@ -915,13 +922,14 @@ dependencies = [ [[package]] name = "ethers-ccip-read" -version = "0.1.0" -source = "git+https://github.com/lucemans/ethers-ccip-read?branch=main#64ff7552384e1742cc62958c46c7384bed5ae938" +version = "0.1.1" +source = "git+https://github.com/ensdomains/ethers-ccip-read?branch=main#5669e42e13bca733d34bbcfb7896a68af5ca79a2" dependencies = [ "async-recursion", "async-trait", "ethers-core", "ethers-providers", + "futures-util", "reqwest", "serde_json", "thiserror", @@ -1528,6 +1536,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + [[package]] name = "httparse" version = "1.8.0" @@ -2033,7 +2047,7 @@ version = "0.10.52" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "foreign-types", "libc", @@ -2464,7 +2478,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -2473,7 +2487,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -2664,7 +2678,7 @@ version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", @@ -2826,7 +2840,7 @@ version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -3402,6 +3416,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-http" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8bd22a874a2d0b70452d5597b12c537331d49060824a95f49f108994f94aa4c" +dependencies = [ + "bitflags 2.3.3", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-layer" version = "0.3.2" diff --git a/Cargo.toml b/Cargo.toml index 1eec1f8..1784d41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,10 @@ license = "GPL-3.0" homepage = "enstate.rs" description = "enstate" repository = "https://github.com/v3xlabs/enstate" -authors = ["Luc van Kampen ", "Miguel Piedrafita "] +authors = [ + "Luc van Kampen ", + "Miguel Piedrafita ", +] [dependencies] ethers = "2" @@ -20,7 +23,9 @@ tokio = { version = "1.28.0", features = ["full"] } utoipa = { version = "3.0.3", features = ["axum_extras"] } utoipa-swagger-ui = { version = "3.0.2", features = ["axum"] } redis = { version = "0.23.0", features = ["connection-manager", "tokio-comp"] } -ethers-ccip-read = { git = "https://github.com/lucemans/ethers-ccip-read", branch = "main" } +ethers-ccip-read = { git = "https://github.com/ensdomains/ethers-ccip-read", branch = "main" } +tower-http = { version = "0.4.1", features = ["cors", "tracing"] } + [build-dependencies] chrono = "0.4.24" diff --git a/src/http.rs b/src/http.rs index 8080a39..740c772 100644 --- a/src/http.rs +++ b/src/http.rs @@ -3,6 +3,7 @@ use axum::{routing::get, Router}; use std::net::SocketAddr; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; +use tower_http::cors::CorsLayer; use crate::routes; @@ -33,6 +34,7 @@ impl App { pub fn setup(state: AppState) -> App { let router = Router::new() + .layer(CorsLayer::permissive()) .merge(SwaggerUi::new("/docs").url("/docs/openapi.json", ApiDoc::openapi())) .route("/", get(routes::root::get)) .route("/a/:address", get(routes::address::get))