Skip to content

rest handler options #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/middleware/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions test/rest.middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down