@@ -9,33 +9,32 @@ module.exports = {
99 const corsPreflight = { }
1010 await BbPromise . all (
1111 this . getAllServiceProxies ( ) . map ( async ( serviceProxy ) => {
12- Object . keys ( serviceProxy ) . forEach ( async ( functionName ) => {
13- await this . checkAllowedService ( functionName )
14- const http = serviceProxy [ functionName ]
15- http . path = await this . getProxyPath ( serviceProxy [ functionName ] )
16- http . method = await this . getProxyMethod ( serviceProxy [ functionName ] )
17-
18- if ( serviceProxy [ functionName ] . cors ) {
19- http . cors = await this . getCors ( serviceProxy [ functionName ] )
20-
21- const cors = corsPreflight [ http . path ] || { }
22-
23- cors . headers = _ . union ( http . cors . headers , cors . headers )
24- cors . methods = _ . union ( http . cors . methods , cors . methods )
25- cors . origins = _ . union ( http . cors . origins , cors . origins )
26- cors . origin = http . cors . origin || '*'
27- cors . allowCredentials = cors . allowCredentials || http . cors . allowCredentials
28-
29- // when merging, last one defined wins
30- if ( _ . has ( http . cors , 'maxAge' ) ) {
31- cors . maxAge = http . cors . maxAge
32- }
33-
34- corsPreflight [ http . path ] = cors
12+ const serviceName = this . getServiceName ( serviceProxy )
13+ await this . checkAllowedService ( serviceName )
14+ const http = serviceProxy [ serviceName ]
15+ http . path = await this . getProxyPath ( serviceProxy [ serviceName ] )
16+ http . method = await this . getProxyMethod ( serviceProxy [ serviceName ] )
17+
18+ if ( serviceProxy [ serviceName ] . cors ) {
19+ http . cors = await this . getCors ( serviceProxy [ serviceName ] )
20+
21+ const cors = corsPreflight [ http . path ] || { }
22+
23+ cors . headers = _ . union ( http . cors . headers , cors . headers )
24+ cors . methods = _ . union ( http . cors . methods , cors . methods )
25+ cors . origins = _ . union ( http . cors . origins , cors . origins )
26+ cors . origin = http . cors . origin || '*'
27+ cors . allowCredentials = cors . allowCredentials || http . cors . allowCredentials
28+
29+ // when merging, last one defined wins
30+ if ( _ . has ( http . cors , 'maxAge' ) ) {
31+ cors . maxAge = http . cors . maxAge
3532 }
3633
37- events . push ( { functionName, http } )
38- } )
34+ corsPreflight [ http . path ] = cors
35+ }
36+
37+ events . push ( { serviceName, http } )
3938 } )
4039 )
4140 return {
@@ -51,6 +50,7 @@ module.exports = {
5150 `Invalid APIG proxy "${ serviceName } ".` ,
5251 ` This plugin supported Proxies are: ${ allowedProxies . join ( ', ' ) } .`
5352 ] . join ( '' )
53+ console . log ( errorMessage )
5454 return BbPromise . reject ( new this . serverless . classes . Error ( errorMessage ) )
5555 }
5656 } ,
0 commit comments