Skip to content

Commit

Permalink
fix(examples): static routes uses new route struct
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Sep 23, 2022
1 parent 81efd29 commit f4b6822
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions examples/static-routes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use hyper::service::{make_service_fn, service_fn};
use once_cell::sync::Lazy;
use std::{convert::Infallible, net::SocketAddr};
use viz::{
types::Params, IntoResponse, Method, Request, RequestExt, Response, Result, Router, Server,
StatusCode, Tree,
types::{Params, Route},
IntoResponse, Method, Request, RequestExt, Response, Result, Router, Server, StatusCode, Tree,
};

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

0 comments on commit f4b6822

Please sign in to comment.