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:
parent
9fb67315f9
commit
4735efa41f
|
@ -1046,7 +1046,7 @@ module.exports = function(registry) {
|
|||
*/
|
||||
Model.createOptionsFromRemotingContext = function(ctx) {
|
||||
return {
|
||||
accessToken: ctx.req.accessToken,
|
||||
accessToken: ctx.req ? ctx.req.accessToken : null,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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: []};
|
||||
|
|
Loading…
Reference in New Issue