Coder Social home page Coder Social logo

Comments (4)

PavelPZ avatar PavelPZ commented on July 17, 2024 1

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.

isoos avatar isoos commented on July 17, 2024 1

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.

jonasfj avatar jonasfj commented on July 17, 2024

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.

jonasfj avatar jonasfj commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.