File tree 2 files changed +12
-14
lines changed 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -22,17 +22,9 @@ module.exports = rest;
22
22
* @header loopback.rest()
23
23
*/
24
24
25
- function rest ( options ) {
26
- options = options || { } ;
25
+ function rest ( ) {
27
26
var tokenParser = null ;
28
27
var contextHandler = null ;
29
- if ( options . context ) {
30
- var contextOptions = options . context ;
31
- if ( typeof contextOptions !== 'object' ) {
32
- contextOptions = { } ;
33
- }
34
- contextHandler = loopback . context ( contextOptions ) ;
35
- }
36
28
return function restApiHandler ( req , res , next ) {
37
29
var app = req . app ;
38
30
var handler = app . handler ( 'rest' ) ;
@@ -44,9 +36,16 @@ function rest(options) {
44
36
}
45
37
46
38
var handlers = [ ] ;
47
- if ( options . context ) {
39
+ var remotingOptions = app . get ( 'remoting' ) || { } ;
40
+
41
+ var contextOptions = remotingOptions . context ;
42
+ if ( contextOptions !== false && ! contextHandler ) {
43
+ if ( typeof contextOptions !== 'object' )
44
+ contextOptions = { } ;
45
+ contextHandler = loopback . context ( contextOptions ) ;
48
46
handlers . push ( contextHandler ) ;
49
47
}
48
+
50
49
if ( app . isAuthEnabled ) {
51
50
if ( ! tokenParser ) {
52
51
// NOTE(bajtos) It would be better to search app.models for a model
@@ -66,5 +65,3 @@ function rest(options) {
66
65
} , next ) ;
67
66
} ;
68
67
}
69
-
70
-
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ describe('loopback.rest', function() {
136
136
}
137
137
138
138
it ( 'should enable context using loopback.context' , function ( done ) {
139
- app . use ( loopback . context ( { enableHttpContext : true } ) ) ;
139
+ app . use ( loopback . context ( { enableHttpContext : true } ) ) ;
140
140
app . enableAuth ( ) ;
141
141
app . use ( loopback . rest ( ) ) ;
142
142
@@ -145,7 +145,8 @@ describe('loopback.rest', function() {
145
145
146
146
it ( 'should enable context with loopback.rest' , function ( done ) {
147
147
app . enableAuth ( ) ;
148
- app . use ( loopback . rest ( { context : { enableHttpContext : true } } ) ) ;
148
+ app . set ( 'remoting' , { context : { enableHttpContext : true } } ) ;
149
+ app . use ( loopback . rest ( ) ) ;
149
150
150
151
invokeGetToken ( done ) ;
151
152
} ) ;
You can’t perform that action at this time.
0 commit comments