Support remoting adapters with no ctx.req object

Fix `Model.createOptionsFromRemotingContext()` to correctly handle
the case where `ctx.req` is not defined, e.g. when using
websocket-based adapters.
This commit is contained in:
Piero Maltese 2017-04-26 13:07:19 +01:00 committed by Miroslav Bajtoš
parent 9fb67315f9
commit 4735efa41f
No known key found for this signature in database
GPG Key ID: 797723F23CE0A94A
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: []};