OK so I am not sure exactly why this is happening. I tried searching for this but I am not sure how to word it - something like "multiple url segments not firing route." ?
Either way here we go...
Using node.js and Express: I have a route in my app.js that looks like this:
app.get('/kosk/:id/:key', kosk.kosk);
If I then go to (http://my.nodeserv.com:8080/kosk/451/123456) I get a 404 not found from the server.
BUT if I do this:
app.get('/kosk/:id', kosk.kosk);
And then go here (http://my.nodeserv.com:8080/kosk/451) - all works fine, the route triggers and I get my param.
The code in the route is set up to handle the items coming in, but I don't understand why the route in this format is not triggered. Again, node answers back with a 404 not found for the multiple segment url. Any ideas? I am hoping I have just missed something simple and can't see around it. Thanks in advance for any help/ideas!
According to your snippet it should work. You may want to verify that it's not something else by making sure the following works:
app.get('/foo/:bar/:baz', function(req, res) {
res.json({
bar: req.params.bar,
baz: req.params.baz
});
});
Sending a GET request to http://localhost:3000/foo/123/456 should respond with:
{
"bar": "123",
"baz": "456"
}
I just did this by creating a new express project and defining the above route for sanity. It worked well for me so I think it might be some other part of your app.js/server.js file that's giving you this problem.