Looks like there's already an option for nesting routes with a module:
https://github.com/visionmedia/express-namespace. Very useful for using
this pattern.

Cheers,
Gustavo

 Martin Wawrusch <[email protected]> wrote:

> SAme here, we use that pattern for a while now, works like a charm and is
> great for testing too. Just make sure that you push  info downstream, not
> upstream (e.g. some start.js requires the route files, and instantiates
> them and passes app and whatever other settings, perhaps database,
> downstream). That way it is very easy to debug, if you even have to :-)
>
>
> On Sat, Jun 2, 2012 at 8:13 AM, Gustavo Machado <[email protected]>wrote:
>
>> In our team, we use the pattern Glenn Block described, and it's a very
>> cool way of organizing your routes. What we do, is add a "hook" method in
>> each resource, and we pass the "app" object so that every resource gets to
>> define it's own endpoints. The only problem I've seen so far, is that you
>> don't have all the routes in one place, so I think that something like this
>> could help "isolate" routes:
>>
>> https://github.com/visionmedia/express/pull/1156
>>
>> Not such a big deal though.
>>
>> Cheers!
>> Gustavo
>>
>>
>> On Thu, May 31, 2012 at 1:34 PM, tjholowaychuk <[email protected]>wrote:
>>
>>> the pattern you're describing is what I prefer to do with express apps
>>> as well.
>>> some people like the "convention over configuration" sort of API
>>> better, aka
>>> something more like express-resource, but personally I find a simple
>>> list of
>>> routes is by far the easiest to scan over. Plus writing app.get('/
>>> dogs', dogs.index)
>>> vs exports.index = function(){} and having the framework automatically
>>> know
>>> what to do with this method really doesn't save that much time if any
>>> since
>>> you're introducing more obscurity
>>>
>>> On May 31, 8:55 am, Glenn Scott <[email protected]> wrote:
>>> > I want to build out an API using restify.    I'd like to lay out the
>>> > project logically so it doesn't become a mess as it grows, but I also
>>> > don't want to get precious about it.  I'm looking for advice.
>>> >
>>> > I was thinking that in the main module ("api.js" ) I would put all the
>>> > routes for every resource; and for the callbacks in each route I would
>>> > put the name of a handler that I export from a module that corresponds
>>> > to the resource, e.g., given a resource "dogs":
>>> >
>>> > api.js:
>>> > --------
>>> >
>>> >    var apiDogs = require( './lib/dogs.js');
>>> >    server.get('/dogs', apiDogs.dogHandler );
>>> >
>>> > dogs.js
>>> > ----------
>>> >
>>> >    exports.dogHandler = function(req, res, next ) {
>>> >       // do lots of stuff here
>>> >       return next();
>>> >    });
>>> >
>>> > Is this the right pattern?  Is there a better one?   Should I just put
>>> > everything into api.js and calm down?
>>>
>>> --
>>> Job Board: http://jobs.nodejs.org/
>>> Posting guidelines:
>>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>>
>>
>>  --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>
>
>
>
>
>  --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to