Route Conditions / Method Not Allowed

438 views
Skip to first unread message

Nick Parsons

unread,
Jan 23, 2013, 4:55:06 PM1/23/13
to res...@googlegroups.com
I cannot for the life of me figure out why I'm getting back a method not allowed error when attempting to access an endpoint.

This works:
app.post('/submissions', controllers.submissions.create); (passing client and sweepstakes id as URL params)

And this fails:
app.post('/clients/:client_id/sweepstakes/:sweepstakes_id/submissons', controllers.submissions.create);

Is there something weird going on behind the scenes with that longer URL? The only thing that I could think of is some kind of route condition type error, but I commented out all of the other routes to isolate the issue and it happens on any URL that pushes past 2 resources (e.g. client or sweepstakes id). 

Any pointers on how to better track down what's going on would be extremely helpful. I come from a PHP background, and the tools on the node side are completely different.

Mark Cavage

unread,
Jan 23, 2013, 4:59:36 PM1/23/13
to res...@googlegroups.com
Hey Nick,

I'd need to see either a server trace of what came in or a wireshark to tell you what you're doing - to get a  server trace, pass in a bunyan logger and set the level to trace:

var server = restify.createServer({
    log: bunyan.createLogger({
        stream:process.stdout,
        level: 'trace',
        name: 'foo',
        serializers: restify.bunyan.serializers
    })
});


then run it like:  node foo.js | bunyan

(or just save the raw json output, and read it later with the bunyan CLI).

m

Nick Parsons

unread,
Jan 23, 2013, 5:13:01 PM1/23/13
to res...@googlegroups.com
Thank you for getting back. I ran that trace, and I can't make anything of it,  but hopefully you can.

Mark Cavage

unread,
Jan 23, 2013, 8:23:30 PM1/23/13
to res...@googlegroups.com
This took me a bunch of looks, but you have a typo (*submissions*):

app.post('/clients/:client_id/sweepstakes/:sweepstakes_id/submissons', controllers.submissions.create);

A local test of mine and with the right spelling it works fine.

m

Nick Parsons

unread,
Jan 23, 2013, 8:28:02 PM1/23/13
to res...@googlegroups.com
Well, that's embarrassing :) Thanks again for your help. I apologize for not taking the time to realize that was the issue.

Mark Cavage

unread,
Jan 23, 2013, 9:12:32 PM1/23/13
to res...@googlegroups.com
No worries - it's hard to deduce that from a 405 - it's not like restify told you you have a typo ;)

Nick Parsons

unread,
Jan 24, 2013, 12:24:43 PM1/24/13
to res...@googlegroups.com
Interesting enough, the spelling issue fixed my original bug, but introduced another that fits into this chain. When calling a route to similar to another, by design it triggers the first available route.

So, when I'm calling /clients/:client_id/sweepstakes/:sweepstakes_id/submissions/export, Restify thinks that I am trying to call /clients/:client_id/sweepstakes/:sweepstakes_id/submissions/:submission_id. Any way around that?

Mark Cavage

unread,
Jan 24, 2013, 12:31:28 PM1/24/13
to res...@googlegroups.com

I'm on a plane today so I can't really look in detail, but from that description you would need to place ...export first in the route definitions since what you describe is valid for both rules.

Message has been deleted

Ryan Kelly

unread,
Feb 18, 2013, 8:45:46 PM2/18/13
to res...@googlegroups.com
(I posted this on another thread, but this one is more appropriate)

I have had an issue calling my restify api from backbone.js as well. everything works well with a curl command, specifying a different origin. However, it is not working with my backbone.js application. I have added the stack trace and my server.js settings here - https://gist.github.com/remotevision/4982339

any thoughts?

Ryan Kelly

unread,
Feb 18, 2013, 9:31:38 PM2/18/13
to res...@googlegroups.com
ugh, nevermind. I had replaced the restify project with what is in npm, not the version from the master:branch. Once I updated it, everything worked fine. false alarm :-)
Reply all
Reply to author
Forward
0 new messages