@@ -30,7 +30,7 @@ router._sanitizeRequestUrl = function(req) {
30
30
host : req . hostname ,
31
31
pathname : req . originalUrl || req . url ,
32
32
query : req . query
33
- } ) ;
33
+ } ) ;
34
34
35
35
return requestUrl . replace ( / ( p a s s w o r d = ) .* ?( & | $ ) / ig, '$1<hidden>$2' ) ;
36
36
} ;
@@ -41,13 +41,13 @@ router._allRequestData = function(req,res,next){
41
41
var newRequestData = _ . assignIn ( requestData , req . params , req . body , req . query ) ;
42
42
if ( newRequestData [ key ] ) {
43
43
return newRequestData [ key ] ;
44
- } else if ( defaultValue ) {
44
+ } else if ( defaultValue ) {
45
45
return defaultValue ;
46
- } else {
46
+ } else {
47
47
return false ;
48
- }
49
- } ;
50
- next ( ) ;
48
+ }
49
+ } ;
50
+ next ( ) ;
51
51
} ;
52
52
53
53
router . _enforceUserIdAndAppId = function ( req , res , next ) {
@@ -56,11 +56,11 @@ router._enforceUserIdAndAppId = function(req,res,next){
56
56
var developer = req . param ( 'developer' ) ;
57
57
if ( ! userId ) {
58
58
return res . badRequest ( false , 'No userId parameter was passed in the payload of this request. Please pass a userId.' ) ;
59
- } else if ( ! appId ) {
59
+ } else if ( ! appId ) {
60
60
return res . badRequest ( false , 'No appId parameter was passed in the payload of this request. Please pass an appId.' ) ;
61
- } else if ( ! developer ) {
61
+ } else if ( ! developer ) {
62
62
return res . badRequest ( false , 'No developer parameter was passed in the payload of this request. Please pass a developer id.' ) ;
63
- } else {
63
+ } else {
64
64
req . userId = userId ;
65
65
req . appId = appId ;
66
66
req . developer = developer ;
@@ -69,7 +69,7 @@ router._enforceUserIdAndAppId = function(req,res,next){
69
69
req . body . createdBy = userId ;
70
70
req . body . developer = developer ;
71
71
next ( ) ;
72
- }
72
+ }
73
73
} ;
74
74
75
75
router . _APICache = function ( req , res , next ) {
@@ -85,11 +85,11 @@ router._APICache = function(req,res,next){
85
85
key . push ( req . get ( 'user-agent' ) ) ;
86
86
if ( req . userId ) {
87
87
key . push ( req . userId ) ;
88
- }
89
- if ( req . appId ) {
88
+ }
89
+ if ( req . appId ) {
90
90
key . push ( req . appId ) ;
91
- }
92
- req . cacheKey = key ;
91
+ }
92
+ req . cacheKey = key ;
93
93
// Remember to delete cache when you get a POST call
94
94
// Only cache GET calls
95
95
if ( req . method === 'GET' ) {
@@ -99,22 +99,22 @@ req.cacheKey = key;
99
99
if ( ! resp ) {
100
100
// Will be set on successful response
101
101
next ( ) ;
102
- } else {
102
+ } else {
103
103
res . ok ( resp , true ) ;
104
- }
105
- } )
104
+ }
105
+ } )
106
106
. catch ( function ( err ) {
107
107
log . error ( 'Failed to get cached data: ' , err ) ;
108
108
// Don't block the call because of this failure.
109
109
next ( ) ;
110
- } ) ;
111
- } else {
110
+ } ) ;
111
+ } else {
112
112
if ( req . method === 'POST' || req . method === 'PUT' || req . method === 'PUSH' ) {
113
113
req . cache . del ( req . cacheKey )
114
114
. then ( ) ; // No delays
115
+ }
116
+ next ( ) ;
115
117
}
116
- next ( ) ;
117
- }
118
118
119
119
} ;
120
120
@@ -134,7 +134,7 @@ router.use(function(req,res,next){
134
134
user : req . userId ,
135
135
device : req . get ( 'user-agent' ) ,
136
136
createdAt : new Date ( )
137
- } ;
137
+ } ;
138
138
139
139
// Dump it in the queue
140
140
queue . create ( 'logRequest' , reqLog )
@@ -172,7 +172,7 @@ limiter({
172
172
expire : config . rateLimitExpiry * 1 ,
173
173
onRateLimited : function ( req , res , next ) {
174
174
next ( { message : 'Rate limit exceeded' , statusCode : 429 } ) ;
175
- }
175
+ }
176
176
} ) ;
177
177
178
178
@@ -200,21 +200,22 @@ router.use('/', initialize);
200
200
//
201
201
//
202
202
203
-
204
- // Make userId compolsory in every request
205
- router . use ( router . _enforceUserIdAndAppId ) ;
203
+ if ( config . enforceUserIdAppIdDeveloperId === 'yes' ) {
204
+ // Make userId compolsory in every request
205
+ router . use ( router . _enforceUserIdAndAppId ) ;
206
+ }
206
207
207
208
// Should automatically load routes
208
209
// Other routes here
209
210
var ourRoutes = { } ;
210
211
var normalizedPath = require ( "path" ) . join ( __dirname , "./" ) ;
211
212
212
213
require ( "fs" ) . readdirSync ( normalizedPath ) . forEach ( function ( file ) {
213
- var splitFileName = file . split ( '.' ) ;
214
- if ( splitFileName [ 0 ] !== 'index' && splitFileName [ 0 ] !== 'initialize' ) {
215
- ourRoutes [ splitFileName [ 0 ] ] = require ( './' + splitFileName [ 0 ] ) ;
216
- router . use ( '/' , ourRoutes [ splitFileName [ 0 ] ] ) ;
217
- }
214
+ var splitFileName = file . split ( '.' ) ;
215
+ if ( splitFileName [ 0 ] !== 'index' && splitFileName [ 0 ] !== 'initialize' ) {
216
+ ourRoutes [ splitFileName [ 0 ] ] = require ( './' + splitFileName [ 0 ] ) ;
217
+ router . use ( '/' , ourRoutes [ splitFileName [ 0 ] ] ) ;
218
+ }
218
219
} ) ;
219
220
220
221
router . use ( function ( req , res , next ) { // jshint ignore:line
0 commit comments