|
2 | 2 | #![deny(rust_2018_idioms)]
|
3 | 3 |
|
4 | 4 | use hyper::service::{make_service_fn, service_fn};
|
5 |
| -use hyper::{Body, Error, Request, Response, Server, StatusCode}; |
| 5 | +use hyper::{Body, Error, Request, Response, Server, StatusCode, Method}; |
6 | 6 | use primitives::adapter::Adapter;
|
7 | 7 | use primitives::Config;
|
8 | 8 | use slog::{error, info, Logger};
|
9 | 9 |
|
10 | 10 | pub mod routes {
|
11 | 11 | pub mod channel;
|
| 12 | + pub mod cfg { |
| 13 | + use hyper::{Body, Response}; |
| 14 | + use crate::ResponseError; |
| 15 | + use primitives::Config; |
| 16 | + |
| 17 | + pub fn return_config(config: &Config) -> Result<Response<Body>, ResponseError> { |
| 18 | + let config_str = serde_json::to_string(config)?; |
| 19 | + |
| 20 | + Ok(Response::builder().body(Body::from(config_str)).unwrap()) |
| 21 | + } |
| 22 | + } |
12 | 23 | }
|
13 | 24 |
|
14 | 25 | pub mod access;
|
@@ -43,7 +54,7 @@ impl<A: Adapter + 'static> Application<A> {
|
43 | 54 | async move {
|
44 | 55 | Ok::<_, Error>(service_fn(move |req| {
|
45 | 56 | let adapter_config = adapter_config.clone();
|
46 |
| - async move { Ok::<_, Error>(handle_routing(req, adapter_config.0).await) } |
| 57 | + async move { Ok::<_, Error>(handle_routing(req, adapter_config).await) } |
47 | 58 | }))
|
48 | 59 | }
|
49 | 60 | });
|
|
71 | 82 | }
|
72 | 83 | }
|
73 | 84 |
|
74 |
| -async fn handle_routing(req: Request<Body>, adapter: impl Adapter) -> Response<Body> { |
75 |
| - if req.uri().path().starts_with("/channel") { |
| 85 | +async fn handle_routing(req: Request<Body>, (adapter, config): (impl Adapter, Config)) -> Response<Body> { |
| 86 | + if req.uri().path().starts_with("/cfg") && req.method() == Method::GET { |
| 87 | + crate::routes::cfg::return_config(&config) |
| 88 | + }else if req.uri().path().starts_with("/channel") { |
76 | 89 | crate::routes::channel::handle_channel_routes(req, adapter).await
|
77 | 90 | } else {
|
78 | 91 | Err(ResponseError::NotFound)
|
|
0 commit comments