@@ -242,6 +242,7 @@ Canned.prototype.respondWithAny = function (httpObj, files, cb) {
242
242
}
243
243
244
244
Canned . prototype . responder = function ( body , req , res ) {
245
+ var responseHandler
245
246
var httpObj = { }
246
247
var that = this
247
248
var parsedurl = url . parse ( req . url )
@@ -263,13 +264,10 @@ Canned.prototype.responder = function(body, req, res) {
263
264
return response . send ( )
264
265
}
265
266
266
- var paths = lookup . getPaths ( httpObj . pathname . join ( '/' ) , that . wildcard ) ;
267
+ var paths = lookup ( httpObj . pathname . join ( '/' ) , that . wildcard ) ;
267
268
paths . splice ( 0 , 1 ) ; // The first path is the default
268
269
269
- // Find a response for the first path
270
- that . findResponse ( httpObj , responseHandler ) ;
271
-
272
- function responseHandler ( err , resp ) {
270
+ responseHandler = function ( err , resp ) {
273
271
if ( err ) {
274
272
// Try more paths, if there are any still
275
273
if ( paths . length > 0 ) {
@@ -283,6 +281,10 @@ Canned.prototype.responder = function(body, req, res) {
283
281
}
284
282
return resp . send ( ) ;
285
283
}
284
+
285
+ // Find a response for the first path
286
+ that . findResponse ( httpObj , responseHandler ) ;
287
+
286
288
}
287
289
288
290
Canned . prototype . findResponse = function ( httpObj , cb ) {
@@ -292,16 +294,16 @@ Canned.prototype.findResponse = function(httpObj, cb) {
292
294
if ( err ) {
293
295
that . _responseForFile ( httpObj , files , function ( err , resp ) {
294
296
if ( err ) {
295
- that . respondWithAny ( httpObj , files , cb ) ;
297
+ that . respondWithAny ( httpObj , files , cb )
296
298
} else {
297
- return cb ( null , resp ) ;
299
+ cb ( null , resp )
298
300
}
299
301
} )
300
302
} else {
301
303
if ( stats . isDirectory ( ) ) {
302
- that . respondWithDir ( httpObj , cb ) ;
304
+ that . respondWithDir ( httpObj , cb )
303
305
} else {
304
- return cb ( null , new Response ( 'html' , '' , 500 , httpObj . res ) ) ;
306
+ cb ( null , new Response ( 'html' , '' , 500 , httpObj . res ) )
305
307
}
306
308
}
307
309
} )
0 commit comments