routes order when using nodejs
does arrangement or order of routes matter in nodejs when building api's because I currently have my routes some with jwt tokens and others without tokens but when I try to access routes without tokens insomnia asks that add a jtw token, is that a bug or should I re arrange my routes?
4 Replies
It does, routes are processed from top to bottom so if you added your auth middleware somewhere in between you'll run into this sort of issues.
Alright thank you,so I need to put all my routes that dont need auth middlware first?
Yes, or define the auth middleware in the route itself. That way you don't have to worry about ordering them, for this use case anyway.
Thanks @Joao