@@ -76,8 +76,7 @@ export class ExpressExtension implements KitesExtension {
7676 }
7777
7878 configureViewEngine ( app : Express , opts : any ) {
79- var configView = this . kites . emit ( 'express:config:view' , app , opts ) ;
80- if ( configView ) {
79+ if ( this . kites . emit ( 'express:config:view' , app , opts ) ) {
8180 this . kites . logger . debug ( 'Express view engine has customized by user!' ) ;
8281 return ;
8382 }
@@ -145,15 +144,6 @@ export class ExpressExtension implements KitesExtension {
145144
146145 configureExpressApp ( app : Express , kites : KitesInstance ) {
147146 kites . express . app = app ;
148- if ( kites . emit ( 'before:express:config' , app ) ) {
149- kites . logger . info ( 'Express use custom config!' ) ;
150- return ;
151- }
152-
153- app . options ( '*' , cors ( {
154- methods : [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'MERGE' ] ,
155- origin : true
156- } ) ) ;
157147
158148 // show powered by
159149 if ( ! this . options . poweredBy ) {
@@ -165,6 +155,11 @@ export class ExpressExtension implements KitesExtension {
165155 } ) ;
166156 }
167157
158+ // default config
159+ app . options ( '*' , cors ( {
160+ methods : [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'MERGE' ] ,
161+ origin : true
162+ } ) ) ;
168163 app . use ( bodyParser . urlencoded ( {
169164 extended : false ,
170165 limit : this . options . inputRequestLimit || '10mb'
@@ -175,19 +170,22 @@ export class ExpressExtension implements KitesExtension {
175170 app . use ( cookieParser ( ) ) ;
176171 app . use ( cors ( ) ) ;
177172
178- kites . logger . debug ( 'Express expanding ...' ) ;
179-
173+ // extend express mixin
180174 app . use ( mixinReq ( kites ) ) ;
181175 app . use ( mixinRes ( kites ) ) ;
182176 app . use ( mixinResView ( kites ) ) ;
183177
178+ kites . logger . debug ( 'Express expanding ...' ) ;
179+ kites . emit ( 'before:express:config' , app ) ;
180+
184181 // default routes
185182 app . use ( '/_kites' , defaultRouter ( ) ) ;
186183
187184 kites . logger . debug ( 'Express starting configure ...' ) ;
188185 kites . emit ( 'express:config' , app ) ;
189186
190- // config static file
187+ // config static assets
188+ kites . emit ( 'express:config:static' , app ) ;
191189 if ( typeof this . options . static === 'string' ) {
192190 kites . logger . debug ( 'Express serve static files at: ' + this . options . static ) ;
193191 app . use ( express . static ( this . options . static ) ) ;
0 commit comments