Skip to content

Commit 093bbdd

Browse files
authored
Merge pull request #170 from AdExNetwork/cfg-route
/cfg route
2 parents 02b1edd + 1ea3cef commit 093bbdd

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

primitives/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ lazy_static! {
1515
}
1616

1717
#[derive(Serialize, Deserialize, Debug, Clone)]
18+
#[serde(rename_all(serialize = "SCREAMING_SNAKE_CASE"))]
1819
pub struct Config {
1920
pub identity: Option<String>, // should not be here maybe?
2021
pub max_channels: u32,

sentry/src/lib.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
#![deny(rust_2018_idioms)]
33

44
use hyper::service::{make_service_fn, service_fn};
5-
use hyper::{Body, Error, Request, Response, Server, StatusCode};
5+
use hyper::{Body, Error, Method, Request, Response, Server, StatusCode};
66
use primitives::adapter::Adapter;
77
use primitives::Config;
88
use slog::{error, info, Logger};
99

1010
pub mod routes {
1111
pub mod channel;
12+
pub mod cfg {
13+
use crate::ResponseError;
14+
use hyper::header::CONTENT_TYPE;
15+
use hyper::{Body, Response};
16+
use primitives::Config;
17+
18+
pub fn return_config(config: &Config) -> Result<Response<Body>, ResponseError> {
19+
let config_str = serde_json::to_string(config)?;
20+
21+
Ok(Response::builder()
22+
.header(CONTENT_TYPE, "application/json")
23+
.body(Body::from(config_str))
24+
.expect("Creating a response should never fail"))
25+
}
26+
}
1227
}
1328

1429
pub mod access;
@@ -43,7 +58,7 @@ impl<A: Adapter + 'static> Application<A> {
4358
async move {
4459
Ok::<_, Error>(service_fn(move |req| {
4560
let adapter_config = adapter_config.clone();
46-
async move { Ok::<_, Error>(handle_routing(req, adapter_config.0).await) }
61+
async move { Ok::<_, Error>(handle_routing(req, adapter_config).await) }
4762
}))
4863
}
4964
});
@@ -71,11 +86,16 @@ where
7186
}
7287
}
7388

74-
async fn handle_routing(req: Request<Body>, adapter: impl Adapter) -> Response<Body> {
75-
if req.uri().path().starts_with("/channel") {
76-
crate::routes::channel::handle_channel_routes(req, adapter).await
77-
} else {
78-
Err(ResponseError::NotFound)
89+
async fn handle_routing(
90+
req: Request<Body>,
91+
(adapter, config): (impl Adapter, Config),
92+
) -> Response<Body> {
93+
match (req.uri().path(), req.method()) {
94+
("/cfg", &Method::GET) => crate::routes::cfg::return_config(&config),
95+
(route, _) if route.starts_with("/channel") => {
96+
crate::routes::channel::handle_channel_routes(req, adapter).await
97+
}
98+
_ => Err(ResponseError::NotFound),
7999
}
80100
.unwrap_or_else(|response_err| match response_err {
81101
ResponseError::NotFound => not_found(),

0 commit comments

Comments
 (0)