@@ -59,7 +59,6 @@ var apphandler = function( req, res, appdir ) {
59
59
} ) ;
60
60
return ;
61
61
}
62
- userapp = app . require ( ) ;
63
62
64
63
res . locals [ "app_name" ] = appname ;
65
64
res . locals [ "app_url" ] = "/app/" + appname ;
@@ -76,40 +75,47 @@ var apphandler = function( req, res, appdir ) {
76
75
return ;
77
76
}
78
77
79
- var routes = [ ] ;
80
- if ( req . route . method === 'get' ) {
81
- routes = userapp . get_routes ;
82
- } else if ( req . route . method === 'post' ) {
83
- routes = userapp . post_routes ;
84
- }
78
+ app . require ( function ( err , userapp ) {
79
+ if ( err ) {
80
+ res . send ( 500 ) ;
81
+ return ;
82
+ }
83
+
84
+ var routes = [ ] ;
85
+ if ( req . route . method === 'get' ) {
86
+ routes = userapp . get_routes ;
87
+ } else if ( req . route . method === 'post' ) {
88
+ routes = userapp . post_routes ;
89
+ }
90
+
91
+ if ( routes ) {
92
+ var found = false ;
93
+ for ( var i in routes ) {
94
+ route = routes [ i ] ;
95
+ if ( route [ 'path' ] instanceof RegExp ) {
96
+ var m = route [ 'path' ] . exec ( apppath ) ;
97
+ if ( m ) {
98
+ userapp [ route [ 'handler' ] ] ( app , req , res , m ) ;
99
+ found = true ;
100
+ break ;
101
+ }
85
102
86
- if ( routes ) {
87
- var found = false ;
88
- for ( var i in routes ) {
89
- route = routes [ i ] ;
90
- if ( route [ 'path' ] instanceof RegExp ) {
91
- var m = route [ 'path' ] . exec ( apppath ) ;
92
- if ( m ) {
93
- userapp [ route [ 'handler' ] ] ( app , req , res , m ) ;
103
+ } else if ( route [ 'path' ] === apppath ) {
104
+ userapp [ route [ 'handler' ] ] ( app , req , res ) ;
94
105
found = true ;
95
106
break ;
96
107
}
97
108
98
- } else if ( route [ 'path' ] === apppath ) {
99
- userapp [ route [ 'handler' ] ] ( app , req , res ) ;
100
- found = true ;
101
- break ;
102
109
}
103
110
111
+ if ( ! found ) {
112
+ res . status ( 404 ) ;
113
+ res . render ( '404' , {
114
+ title : 'error'
115
+ } ) ;
116
+ }
104
117
}
105
-
106
- if ( ! found ) {
107
- res . status ( 404 ) ;
108
- res . render ( '404' , {
109
- title : 'error'
110
- } ) ;
111
- }
112
- }
118
+ } ) ;
113
119
} ) ;
114
120
} ;
115
121
0 commit comments