defining routes as a structure

41 views
Skip to first unread message

shawn wilson

unread,
Sep 8, 2012, 9:29:23 PM9/8/12
to flati...@googlegroups.com
this is what i have is: https://gist.github.com/3681689

i see under the fourth example here http://flatironjs.org/#routing that i can define my routes as a structure. however my code crashes when i try 'curl http://127.0.0.1:3000/test' here:
/node/fr/node_modules/flatiron/lib/flatiron/plugins/http.js:77
        if (!app.router.dispatch(req, res, app.http.onError || union.errorHand
                        ^
TypeError: Object #<Object> has no method 'dispatch'
    at Array.exports.attach.app.createServer.app.server.union.createServer.before [as 1]

Marak Squires

unread,
Sep 8, 2012, 9:35:44 PM9/8/12
to flati...@googlegroups.com
app.router is a Director.router instance. You can't override it like that. Maybe you can try setting app.router.routes, but I don't think that would work either.

There should be an API method for adding routes as JSON. Should be in the README as "mount"

mount(routes, path)

  • routes {object}: Partial routing table to insert into this instance.
  • path {string|Regexp}: Path within the Routing Table to insert the routes into.

Inserts the partial Routing Tableroutes, into the Routing Table for this Router instance at the specified path.

Marak Squires

unread,
Sep 8, 2012, 9:41:58 PM9/8/12
to flati...@googlegroups.com
You can also follow the example you posted which uses the following syntax:

var router = new director.http.Router(routes);

On Sat, Sep 8, 2012 at 6:29 PM, shawn wilson <ag4v...@gmail.com> wrote:

shawn wilson

unread,
Sep 8, 2012, 9:44:04 PM9/8/12
to flati...@googlegroups.com
yes, i just found this:

it still doesn't "work" - i curl and it just sits there, but it isn't crashing ... so, do i still need {"get": function() { ..... res.end(); } } ?
i'm going back to the docs for now...

Marak Squires

unread,
Sep 8, 2012, 9:46:31 PM9/8/12
to flati...@googlegroups.com
The issue is probably with this:

var routes = {
    '/test': {
        get: { "hello": "world" }
    }
}

module.exports = routes;



Not sure what that routing table is suppose to do. The format looks invalid.  
Reply all
Reply to author
Forward
0 new messages