@@ -9,9 +9,32 @@ import { projectConfig } from '../../../project/config'
99export const API_GATEWAY_REST_API = 'ApiGatewayRestApi'
1010
1111export const apiGateway = ExecuteStep . register ( 'ApiGateway' , async ( context ) => {
12- await executor ( context , gatewayRestApi )
1312 await executor ( context , gatewayResources )
14- await executor ( context , gatewayDeployment )
13+ } )
14+
15+ export const gatewayResources = ExecuteStep . register ( 'ApiGateway-Resources' , async ( context ) => {
16+ const endpointsCors = new Map < string , any > ( )
17+ const endpoints = new Map < string , any > ( )
18+ for ( const serviceDefinition of context . publishedFunctions ) {
19+ await executor ( {
20+ context : { ...context , serviceDefinition, endpointsCors, endpoints } ,
21+ name : `ApiGateway-Methods-${ serviceDefinition . service . name } ` ,
22+ method : apiGatewayMethods
23+ } )
24+ }
25+
26+ for ( const [ endpointResourceName , { serviceDefinition, methods, headers, credentials, origin } ] of endpointsCors ) {
27+ await executor ( {
28+ context : { ...context , endpointResourceName, serviceDefinition, methods, headers, credentials, origin } ,
29+ name : `ApiGateway-Method-Options-${ endpointResourceName } ` ,
30+ method : setOptionsMethodResource
31+ } )
32+ }
33+
34+ if ( endpoints . size ) {
35+ await executor ( context , gatewayRestApi )
36+ await executor ( context , gatewayDeployment )
37+ }
1538} )
1639
1740export const gatewayRestApi = ExecuteStep . register ( 'ApiGateway-RestApi' , async ( context ) => {
@@ -71,26 +94,6 @@ export const gatewayRestApi = ExecuteStep.register('ApiGateway-RestApi', async (
7194
7295} )
7396
74- export const gatewayResources = ExecuteStep . register ( 'ApiGateway-Resources' , async ( context ) => {
75- const endpointsCors = new Map < string , any > ( )
76- const endpoints = new Map < string , any > ( )
77- for ( const serviceDefinition of context . publishedFunctions ) {
78- await executor ( {
79- context : { ...context , serviceDefinition, endpointsCors, endpoints } ,
80- name : `ApiGateway-Methods-${ serviceDefinition . service . name } ` ,
81- method : apiGatewayMethods
82- } )
83- }
84-
85- for ( const [ endpointResourceName , { serviceDefinition, methods, headers, credentials, origin } ] of endpointsCors ) {
86- await executor ( {
87- context : { ...context , endpointResourceName, serviceDefinition, methods, headers, credentials, origin } ,
88- name : `ApiGateway-Method-Options-${ endpointResourceName } ` ,
89- method : setOptionsMethodResource
90- } )
91- }
92- } )
93-
9497export const apiGatewayMethods = async ( context ) => {
9598 const { serviceDefinition } = context
9699
@@ -121,7 +124,7 @@ export const apiGatewayMethod = async (context) => {
121124 endpoint = endpoints . get ( pathFragment )
122125 } else {
123126 endpoint = await executor ( {
124- context : { ...context , pathFragment, rootPathFragment, endpoints , pathPart } ,
127+ context : { ...context , pathFragment, rootPathFragment, pathPart } ,
125128 name : `ApiGateway-ResourcePath-${ pathFragment } ` ,
126129 method : apiGatewayPathPart
127130 } )
0 commit comments