Fix `loopback.getCurrentContext`
- ensure the method is always defined - return `null` when the context is not active (we are not inside a request-handling chain)
This commit is contained in:
parent
c29ace3404
commit
8f5aea3e3b
|
@ -185,6 +185,11 @@ loopback.template = function(file) {
|
|||
return ejs.compile(str);
|
||||
};
|
||||
|
||||
loopback.getCurrentContext = function() {
|
||||
// A placeholder method, see lib/middleware/context.js for the real version
|
||||
return null;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Built in models / services
|
||||
*/
|
||||
|
|
|
@ -16,7 +16,7 @@ function createContext(scope) {
|
|||
process.context[scope] = ns;
|
||||
// Set up loopback.getCurrentContext()
|
||||
loopback.getCurrentContext = function() {
|
||||
return ns;
|
||||
return ns && ns.active ? ns : null;
|
||||
};
|
||||
|
||||
chain(juggler);
|
||||
|
|
|
@ -20,6 +20,10 @@ describe('loopback', function() {
|
|||
expect(require('fs').existsSync(loopback.faviconFile), 'file exists')
|
||||
.to.equal(true);
|
||||
});
|
||||
|
||||
it.onServer('has `getCurrentContext` method', function() {
|
||||
expect(loopback.getCurrentContext).to.be.a('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('loopback.createDataSource(options)', function() {
|
||||
|
|
Loading…
Reference in New Issue