that's a bit of a gotcha right now (having to move .use() up) because
of the reason
you mention with mounting the router on the first app.VERB() call.
I've played with
making each app.VERB() call its own separate middleware so that you
can add
middleware in-between, it does work however it's significantly slower.
Moving it
above will have the correct effect but I definitely agree from a
modularity stand-point
it's not the best, I'd like to revisit routes-as-middleware in the
future. Note though you
can also mount entire apps, which would give you this behaviour
On Oct 16, 9:23 am, craigyk <
crai...@nimgs.com> wrote:
> I think I figured out the hard way recently that there is a magical piece
> of middleware called router that get activated on assigning the first
> handler on an express app. I was trying to keep my routes grouped together
> for organization by truing to assign route specific middleware to a url
> before attaching all the handlers. I'm a bit confused as to why routing
> was designed this way? Any pointers on good ways to group handlers and
> specific middleware? Am I just "doing it wrong"?
>
> I wanted to do something like:
>
> app.use '/client', clientlogin
> app.get '/client/posts/:postid', ....
>
app.post '/client/posts/', ...
>
> app.use '/admin', adminlogin # <- doesn't work unless I move it up top...
> app.get '/admin/users/:userid', ....
> app.del '/admin/users/:userid', ....