Merge pull request #3376 from pierissimo/patch-1

Support remoting adapters with no ctx.req object
This commit is contained in:
Miroslav Bajtoš 2017-05-22 15:23:51 +02:00 committed by GitHub
commit f8db64c9c3
2 changed files with 7 additions and 1 deletions

View File

@ -1046,7 +1046,7 @@ module.exports = function(registry) {
*/
Model.createOptionsFromRemotingContext = function(ctx) {
return {
accessToken: ctx.req.accessToken,
accessToken: ctx.req ? ctx.req.accessToken : null,
};
};

View File

@ -964,6 +964,12 @@ describe.onServer('Remote Methods', function() {
});
});
it('sets empty options.accessToken for requests coming from websocket/primus adapters', function() {
const primusContext = {};
const opts = TestModel.createOptionsFromRemotingContext(primusContext);
expect(opts).to.have.property('accessToken', null);
});
it('allows apps to add options before remoting hooks', function(done) {
TestModel.createOptionsFromRemotingContext = function(ctx) {
return {hooks: []};