visionmedia / express-resource

Resourceful routing for Express
1.41k stars 140 forks source link

Namespaced Resources Require Specifying param #36

Closed seanabrahams closed 13 years ago

seanabrahams commented 13 years ago

Works...

app.resource('admin/users', require('./app/resources/admin/users'), { id: 'user' });

Doesn't work...

app.resource('admin/users', require('./app/resources/admin/users'));

In the "Doesn't work..." example the param will be ":admin/user" instead of ":user".

mohamedmansour commented 13 years ago

Sean, oh my, this took me forever to figure it out! I spent numerous hours trying. This fix makes sense and it works on my plate

Reduction:

//
// URLS:
//    Index page: http://localhost:3000/api/
//    Service Index page: http://localhost:3000/api/foo/
//    Service Resource page: http://localhost:3000/api/foo/something
//

var express = require('express')
  , resource = require('../')
  , app = express.createServer();

var api = {
  index: function(req, res){
    res.send('api index');
  }
};

var foo = {
  index: function(req, res){
    res.send('foo index');
  },
  show: function(req, res) {
    res.send('bar all');
  }
};

app.resource('api', api);
app.resource('api/foo', foo, { id: 'foo' });

app.listen(3000);
mohamedmansour commented 13 years ago

I guess this is as designed, I will write up some docs so others wont come to the same issue

mohamedmansour commented 13 years ago

Actually, would be nice if the default was named "id"

mohamedmansour commented 13 years ago

Thanks, works great!