diff --git a/lib/express-restify-mongoose.js b/lib/express-restify-mongoose.js index 96d7bbc2..9c61c045 100644 --- a/lib/express-restify-mongoose.js +++ b/lib/express-restify-mongoose.js @@ -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 ]; @@ -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 = {}; @@ -183,4 +188,4 @@ var restify = function(app, model, options) { }); }; -module.exports.serve = restify; \ No newline at end of file +module.exports.serve = restify;