You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently started a project and I added special middleware to render special pages for 404 and 500 results.
But the issue is that it not run sometimes.
How can I make my middleware trigger if no matching routes in router?
I created very small example program to show the issue:
externcrate gotham;#[macro_use]externcrate gotham_derive;externcrate hyper;externcrate mime;use gotham::router::builder::DefineSingleRoute;use gotham::router::builder::DrawRoutes;use gotham::middleware::Middleware;use gotham::router::Router;use gotham::pipeline::set::new_pipeline_set;use gotham::pipeline::new_pipeline;use gotham::pipeline::set::finalize_pipeline_set;use gotham::router::builder::build_router;use gotham::state::State;use gotham::handler::HandlerFuture;constHELLO_WORLD:&str = "Hello World!";constHELLO_MIDDLE:&str = "Hello World From Middle!";pubfnsay_hello(state:State) -> (State,&'static str){(state,HELLO_WORLD)}#[derive(Clone,NewMiddleware)]pubstructPrintMiddleWare;implMiddlewareforPrintMiddleWare{fncall<Chain>(self,state:State,chain:Chain) -> Box<HandlerFuture>whereChain:FnOnce(State) -> Box<HandlerFuture>,{println!("{:?}", HELLO_MIDDLE);chain(state)}}fnrouter()->Router{let pipelines = new_pipeline_set();let(pipelines,default) = pipelines.add(new_pipeline().add(PrintMiddleWare{}).build(),);let pipeline_set = finalize_pipeline_set(pipelines);let default_chain = (default,());build_router(default_chain, pipeline_set, |route| {// Here will print
route.get_or_head("/").to(say_hello);// Here will print
route.get_or_head("/will-print").to(say_hello);// Will NOT print on /test because no matches// But I want to print})}pubfnmain(){let addr = "127.0.0.1:7878";println!("Listening for requests at http://{}", addr);
gotham::start(addr,router())}
The text was updated successfully, but these errors were encountered:
Thanks for the report @AngelicosPhosphoros . There have been a few similar issues such as #256 or #292. These are definitely things we'd like to address as we improve the router.
I recently started a project and I added special middleware to render special pages for 404 and 500 results.
But the issue is that it not run sometimes.
How can I make my middleware trigger if no matching routes in router?
I created very small example program to show the issue:
The text was updated successfully, but these errors were encountered: