Comments (4)
I prefer the B) option, which allow combination e.g.:
var handler = Cascade()
.add(webSocketHandler)
.add(router.handler)
.add(staticFileHandler)
.add(application)
.handler;
from dart-neats.
We could also have a single wrapper that takes in a Handler
, calls it, and if the result is null
, it returns 404
.
from dart-neats.
The documentation of Router
says:
If multiple routes match the same request, the handler for the first route is called. If the handler returns null the next matching handler will be attempted.
We could of course say that top-level Router.handler
should act differently, it would require a few internal hacks when mounting a router in another router... but that could work.
Note, you don't really need Cascade
with Router
... as you can do:
final app = Router();
app.all('/<.*>', (request) {
return null; // to pass to the next handler...
});
app.get('/index.html', (request) {
return ...
});
If you want a quick work around you can also do:
final app = Router();
// .... <insert all handlers>
// Fallback handler that returns 404, if no earlier handler have returned a response.
app.all('/<.*>', (request) => shelf.Response.notFound(''));
Notice that handlers are matched in the order they are declared.
from dart-neats.
I think we should either:
A) Give an example of how to do Cascade
-like things with Router
, or,
B) Make Router.handler
default to returning 404
.
from dart-neats.
Related Issues (20)
- Doesn't work with Riverpod HOT 4
- router.get method should be able to pass context HOT 6
- add support to execute task in isolated (in background outside the main thread) HOT 3
- Migrate to use same pattern as UrlPattern HOT 3
- get current attempt times HOT 4
- [sanitize_html] Why section tag not allowed? HOT 1
- Should replace | with : in '/user/<userId|[0-9]+>', : looks more like a natural constraint symbol HOT 1
- consider updating the 'repository' pubspec fields with the repo+path_in_the_repo information HOT 4
- Put `lib/` directory into root of vendored package? HOT 4
- package retry -- terminology / semantics HOT 2
- consider this as a host for package:directories? HOT 5
- move top level pubspec into the tool/ dir?
- Enabling retry on any type of thrown errors HOT 2
- Callback for time left until next task. HOT 3
- Allow more/custom labels in `encodePemBlock` HOT 4
- Update to make RetryOptions final is breaking mocks HOT 2
- Could not start() after stop() HOT 1
- Proposal `obtain` / `getOrCreate` function HOT 1
- The updated RFC allows relative URLs in the `location` header, but the package rejects them.
- new update issue 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 dart-neats.