Skip to content

Commit

Permalink
Merge pull request #4307 from chenyukang/yukang-fix-cors
Browse files Browse the repository at this point in the history
Fix RPC cors issue of preflight request
  • Loading branch information
quake authored Jan 19, 2024
2 parents 54b3749 + fdaf61f commit 194d935
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async-trait = "0.1"
axum = "0.6.20"
tokio-util = { version = "0.7.3", features = ["codec"] }
futures-util = { version = "0.3.21" }
tower-http = { version = "0.3.5", features = ["timeout"] }
tower-http = { version = "0.3.5", features = ["timeout", "cors"] }
async-stream = "0.3.3"
ckb-async-runtime = { path = "../util/runtime", version = "= 0.114.0-pre" }

Expand Down
3 changes: 3 additions & 0 deletions rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::net::TcpListener;
use tokio_util::codec::{FramedRead, FramedWrite, LinesCodec, LinesCodecError};
use tower_http::cors::CorsLayer;
use tower_http::timeout::TimeoutLayer;

#[doc(hidden)]
Expand Down Expand Up @@ -84,6 +85,7 @@ impl RpcServer {
enable_websocket: bool,
) -> Result<SocketAddr, AnyError> {
let stream_config = StreamServerConfig::default()
.with_keep_alive(true)
.with_channel_size(4)
.with_pipeline_size(4);

Expand All @@ -94,6 +96,7 @@ impl RpcServer {
.route("/", method_router.clone())
.route("/*path", method_router)
.layer(Extension(Arc::clone(rpc)))
.layer(CorsLayer::permissive())
.layer(TimeoutLayer::new(Duration::from_secs(30)));

if enable_websocket {
Expand Down

0 comments on commit 194d935

Please sign in to comment.