Giter Club home page Giter Club logo

Comments (8)

1602 avatar 1602 commented on July 24, 2024

Done. Check out example app.

from railway-routes.

cayasso avatar cayasso commented on July 24, 2024

This is great stuff, thank you, will let you know if I see any issues.
JB

from railway-routes.

cayasso avatar cayasso commented on July 24, 2024

Hey what about multiple middlewares, like I want one to execute first and then the other one, your example show middleware for just one resource route or namespace, what about if I want have authentication for a posts and then after user authenticate then do a loadUser, user my be used for other actions in other controllers without the need to be authenticated first so for example. In regular express:

get('/post', authenticate, loadUser, function(req, res){}) // multiple mws
get('/comment', loadUser, function(req, res){}) // one mw

from railway-routes.

tj avatar tj commented on July 24, 2024

express also allows arrays:

get('/post', [authenticate, loadUser], fn)

etc, in fact any number of nested arrays is fine, so that should already work with this module even if not explicitly supported

from railway-routes.

cayasso avatar cayasso commented on July 24, 2024

Awesome TJ, I didn't know that!!! is that supported in express 2.5+
Thanks!

from railway-routes.

tj avatar tj commented on July 24, 2024

yup! [foo, bar, baz], [foo, [bar, baz]], [foo, [bar, [baz]] etc, it's all just flattened

from railway-routes.

cayasso avatar cayasso commented on July 24, 2024

Wow wow!!, you see thats why I love express even for things I don't even know :)
Thanks TJ!

from railway-routes.

1602 avatar 1602 commented on July 24, 2024

@cayasso of course you can use this awesome feature within router helpers, just pass function or array of functions to any {middleware: ...} param. It also possible to have nested namespaces with middlewares stack.

from railway-routes.

Related Issues (17)

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.