Skip to content

Commit fab2aac

Browse files
authored
Merge pull request #6 from AIBlockOfficial/v0.1.5
Adding DELETE CORS handling
2 parents a02bdbb + e05adf6 commit fab2aac

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "valence_core"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
edition = "2021"
55
license = "MIT"
66
keywords = ["blockchain", "L2", "peer-to-peer", "P2P"]

src/api/utils.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ pub fn with_node_component<T: Clone + Send>(
1818
warp::any().map(move || comp.clone())
1919
}
2020

21-
/// Easy and simple POST CORS
22-
pub fn post_cors() -> warp::cors::Builder {
21+
fn cors_builder(methods: Vec<&str>) -> warp::cors::Builder {
2322
warp::cors()
2423
.allow_any_origin()
2524
.allow_headers(vec![
@@ -34,26 +33,22 @@ pub fn post_cors() -> warp::cors::Builder {
3433
"Access-Control-Allow-Headers",
3534
"Content-Type",
3635
])
37-
.allow_methods(vec!["POST"])
36+
.allow_methods(methods)
37+
}
38+
39+
/// Easy and simple POST CORS
40+
pub fn post_cors() -> warp::cors::Builder {
41+
cors_builder(vec!["POST", "OPTIONS"])
3842
}
3943

4044
/// Easy and simple GET CORS
4145
pub fn get_cors() -> warp::cors::Builder {
42-
warp::cors()
43-
.allow_any_origin()
44-
.allow_headers(vec![
45-
"Accept",
46-
"User-Agent",
47-
"Sec-Fetch-Mode",
48-
"Referer",
49-
"Origin",
50-
"Access-Control-Request-Method",
51-
"Access-Control-Request-Headers",
52-
"Access-Control-Allow-Origin",
53-
"Access-Control-Allow-Headers",
54-
"Content-Type",
55-
])
56-
.allow_methods(vec!["GET"])
46+
cors_builder(vec!["GET", "OPTIONS"])
47+
}
48+
49+
/// Easy and simple DELETE CORS
50+
pub fn delete_cors() -> warp::cors::Builder {
51+
cors_builder(vec!["DELETE", "OPTIONS"])
5752
}
5853

5954
/// Middleware filter to handle signature verification

0 commit comments

Comments
 (0)