Skip to content

Commit

Permalink
fix(examples): static routes uses RouteInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Oct 4, 2022
1 parent 4c7a0e9 commit 288bf23
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions examples/static-routes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use hyper::service::{make_service_fn, service_fn};
use once_cell::sync::Lazy;
use std::{convert::Infallible, net::SocketAddr};
use std::{convert::Infallible, net::SocketAddr, sync::Arc};
use viz::{
types::{Params, Route},
types::{Params, RouteInfo},
IntoResponse, Method, Request, RequestExt, Response, Result, Router, Server, StatusCode, Tree,
};

Expand Down Expand Up @@ -46,16 +46,16 @@ pub async fn serve(mut req: Request, mut addr: Option<SocketAddr>) -> Result<Res
None
}
}) {
Some(route) => {
Some((handler, route)) => {
if addr.is_some() {
req.extensions_mut().insert(addr.take());
}
req.extensions_mut()
.insert(Route::new(*route.id, route.pattern()));
req.extensions_mut()
.insert(Into::<Params>::into(route.params()));
route
.value
req.extensions_mut().insert(Arc::from(RouteInfo {
id: *route.id,
pattern: route.pattern(),
params: Into::<Params>::into(route.params()),
}));
handler
.call(req)
.await
.unwrap_or_else(IntoResponse::into_response)
Expand Down

0 comments on commit 288bf23

Please sign in to comment.