50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use std::convert::Infallible;
|
|
|
|
use axum::{
|
|
body::Body,
|
|
http::{Request, StatusCode},
|
|
middleware::map_request,
|
|
response::Response,
|
|
routing::*,
|
|
Router,
|
|
};
|
|
use tower::{service_fn, util::BoxService, Service};
|
|
|
|
pub fn secrets_router() -> Router {
|
|
// let middleware = tower::util::MapRequestLayer::new(handler);
|
|
|
|
Router::new().layer(map_request(handler))
|
|
}
|
|
|
|
// async fn handler(Host(hostname): Host, request: Request<Body>) -> &'static str {
|
|
// TODO: Find a solution for this mess
|
|
async fn handler(request: Request<Body>) -> Result<Request<Body>, StatusCode> {
|
|
// let path: Vec<&str> = request.uri().path().split('/').clone().collect();
|
|
// log::info!("path, {:?}", path[1]);
|
|
|
|
let root = service_fn(|req: Request<String>| async move {
|
|
let res = Response::new("Hello, World!".to_string());
|
|
Ok::<_, Infallible>(res)
|
|
});
|
|
let root = BoxService::new(root);
|
|
|
|
let mut routes = vec!["/abc", "/def"];
|
|
routes.sort_unstable_by(|a, b| a.len().cmp(&b.len()));
|
|
|
|
let mut app = Router::new();
|
|
app.as_service().call(request).await.unwrap();
|
|
|
|
// match path[1] {
|
|
// "test" => {
|
|
// log::info!("test route");
|
|
// // TODO: Nest another Router here
|
|
// return Ok(Request::new(Body::empty()));
|
|
// }
|
|
// _ => {
|
|
// log::info!("default");
|
|
// return Err(StatusCode::NOT_FOUND);
|
|
// }
|
|
// }
|
|
|
|
Err(StatusCode::IM_A_TEAPOT)
|
|
}
|