Comments (3)
Should the _
catch all route inherit the middleware just like other routes?
For example:
router! {
use LoggingMiddleware;
GET "/foo" => foo_handler
GET "/bar" => bar_handler
_ => handle_404
}
Should routes handled by handle_404
call the logging middleware like a regular request?
from submillisecond.
Yes, I think so. To stay consistent.
from submillisecond.
I would expect we treat the value after _ =>
to be a handler rather than a subrouter... but what if we want to support a subrouter being there instead?
Sadly, our currently implementation treats handler functions different to subrouters. Subrouters are called directly with subrouter(__req, __params, __reader)
, and handlers with Handler::handle(handler, __req)
.
An example of using a router with the catch all system would be with static_dir!
macro:
router! {
"/static" => {
GET "/foo.txt" => serve_foo
_ => static_dir!("./static")
}
}
The most simple way to treat the value diffrently is to check if it's prefixed with a HTTP method, and if so, treat it as a handler, otherwise subrouter. But that means there wouldn't be an easy way to serve a custom 404 handler if the catchall could be prefixed with handlers. They'd have to do:
router! {
GET "/foo" => foo_handler
GET _ => handle_404
POST _ => handle_404
PATCH _ => handle_404
// ...and so on for each method
}
Perhaps we need to introduce a http keyword for any http method, but to indicate that we treat the value as a handler.
For example:
router! {
GET "/foo" => foo_handler // handler
ANY _ => handle_404 // handler
_ => SUBROUTER_404 // subrouter
}
from submillisecond.
Related Issues (20)
- RUSTSEC-2020-0071: Potential segfault in the time crate HOT 1
- RUSTSEC-2021-0139: ansi_term is Unmaintained HOT 2
- RUSTSEC-2021-0145: Potential unaligned read
- middleware compatibility HOT 1
- Examples don't work HOT 2
- RUSTSEC-2023-0065: Tungstenite allows remote attackers to cause a denial of service
- Session data
- Add a cookie extractor
- Where to put Guards? HOT 6
- Rename `static_dir!` macro to `static_router!`
- Router params don't work in params example HOT 7
- Support `[...]` syntax for multiple middleware in macro
- `params router` benchmark fails, route not matched
- Add support for wildcard routing `/*` HOT 2
- Add WebSocket support
- Create lunatic cli HOT 2
- Allow State passed into handler HOT 1
- Static router doesn't work with `"/"` path
- Support for dependency injection? HOT 2
- Server-Sent Events HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from submillisecond.