Merge pull request #708 from globocom/rest-options
rest handler options
This commit is contained in:
commit
b527405bb8
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue