Merge pull request #708 from globocom/rest-options

rest handler options
This commit is contained in:
Miroslav Bajtoš 2014-10-31 09:27:38 +01:00
commit b527405bb8
2 changed files with 14 additions and 3 deletions

View File

@ -19,13 +19,14 @@ module.exports = rest;
* ```
* For more information, see [Exposing models over a REST API](http://docs.strongloop.com/display/DOC/Exposing+models+over+a+REST+API).
* @header loopback.rest()
* @param {Object} options REST handler options.
*/
function rest() {
function rest(options) {
var tokenParser = null;
return function (req, res, next) {
var app = req.app;
var handler = app.handler('rest');
var handler = app.handler('rest', options);
if(req.url === '/routes') {
res.send(handler.adapter.allRoutes());

View File

@ -75,6 +75,16 @@ describe('loopback.rest', function() {
});
});
it('should support options', function(done) {
app.model(MyModel);
var supportedTypes = ['json', 'application/javascript', 'text/javascript'];
app.use(loopback.rest({supportedTypes: supportedTypes}));
request(app).get('/mymodels')
.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200, done);
});
it('includes loopback.token when necessary', function(done) {
givenUserModelWithAuth();
app.enableAuth();