REST handler options.

This commit is contained in:
Guilherme Cirne 2014-10-29 16:02:01 -02:00
parent 67f8b37562
commit ba6bf3f41b
2 changed files with 14 additions and 3 deletions

View File

@ -12,20 +12,21 @@ module.exports = rest;
/**
* Expose models over REST.
*
*
* For example:
* ```js
* app.use(loopback.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();