Skip to content

Commit 126d252

Browse files
committed
FIX: do not create api gateway without rest endpoint
1 parent 0545663 commit 126d252

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/cli/providers/cloudFormation/context/apiGateway.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,32 @@ import { projectConfig } from '../../../project/config'
99
export const API_GATEWAY_REST_API = 'ApiGatewayRestApi'
1010

1111
export 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

1740
export 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-
9497
export 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

Comments
 (0)