Skip to content

Commit

Permalink
Merge pull request #5 from dhigginbotham/master
Browse files Browse the repository at this point in the history
added option for pluralizing the route -- quite helpful if your schema is already plural, cheers
  • Loading branch information
florianholzapfel committed Jun 21, 2013
2 parents b8ac476 + 53a6d00 commit 91d722b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/express-restify-mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ var restify = function(app, model, options) {
if(!options.prefix) {
options.prefix = "/api";
}
if( ( typeof options.plural === "undefined" ) || ( options.plural === null ) ) {
options.plural = true
}
if(!options.version) {
options.version = "/v1";
}
if(options.middleware) {
if(options.middleware) {
if(!options.middleware instanceof Array) {
var m = options.middleware;
options.middleware = [ m ];
Expand All @@ -44,9 +47,11 @@ var restify = function(app, model, options) {
options.middleware.unshift(cleanQuery);

var queryOptions = {protected: ["skip", "limit", "sort", "populate"], current: {}};

var apiUri = options.plural === true ? "%s%s/%ss" : "%s%s/%s"

var uri_items = util.format('%s%s/%ss', options.prefix, options.version, model.modelName);
var uri_item = util.format('%s%s/%ss/:id', options.prefix, options.version, model.modelName);
var uri_items = util.format(apiUri, options.prefix, options.version, model.modelName);
var uri_item = util.format(apiUri + '/:id', options.prefix, options.version, model.modelName);

function cleanQuery(req, res, next) {
queryOptions.current = {};
Expand Down Expand Up @@ -183,4 +188,4 @@ var restify = function(app, model, options) {
});
};

module.exports.serve = restify;
module.exports.serve = restify;

0 comments on commit 91d722b

Please sign in to comment.