dchester / epilogue

Create flexible REST endpoints and controllers from Sequelize models in your Express app
846 stars 116 forks source link

Epilogue fails when restify.createServer uses a custom name. #151

Closed jgutix closed 8 years ago

jgutix commented 8 years ago

Let's say I initialize my server like this:

var server = restify.createServer({
    name: 'pinche-api'
});

If any of my resources enables the delete controller it will fail with this error:

has no method 'delete'
    at Controller.route (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/Controllers/base.js:76:19)
    at Controller.initialize (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/Controllers/base.js:33:8)
    at Controller (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/Controllers/base.js:9:8)
    at new Delete (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/Controllers/delete.js:8:17)
    at null.<anonymous> (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/Resource.js:69:32)
    at Array.forEach (native)
    at new Resource (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/Resource.js:65:16)
    at Object.epilogue.resource (/Applications/AMPPS/www/pinche/api/node_modules/epilogue/lib/index.js:62:20)

This is happening because https://github.com/dchester/epilogue/blob/master/lib/Controllers/base.js#L73 is specifically comparing app.name === 'restify'

I think if there's other way to detect automatically that restify is used would be great, otherwise an option in the epilogue.initialize method that manually set that you are using restify would be a good solution too. Even tough this is not a big deal or issue, it's just not easy to tell what is the problem based on the error returned.

mbroadst commented 8 years ago

duplicate of #133

jgutix commented 8 years ago

@mbroadst do think that using app.constructor.name instead of app.name would be fine? Because restify always return 'Server' meanwhile express returns 'EventEmitter', if so I can prepare a PR to address this.

mbroadst commented 8 years ago

@jgutix yeah I generally think it's best-effort here, so whatever works best works :smile:

I would say there are two ideals here: