Skip to content

Commit

Permalink
AT-9828: More stage updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rddimon committed Jun 20, 2023
1 parent 5fa3b8a commit 6d36152
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 20 deletions.
16 changes: 2 additions & 14 deletions src/aws/api-gateway-v2-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,13 @@ class APIGatewayV2Wrapper extends APIGatewayBase {
* @param domain: DomainConfig
*/
public async createBasePathMapping(domain: DomainConfig): Promise<void> {
let stage = domain.stage;
if (domain.apiType === Globals.apiTypes.http) {
// find a better way how to implement custom stage for the HTTP API type
stage = Globals.defaultStage;
}

try {
await this.apiGateway.send(
new CreateApiMappingCommand({
ApiId: domain.apiId,
ApiMappingKey: domain.basePath,
DomainName: domain.givenDomainName,
Stage: stage,
Stage: domain.stage,
})
);
Logging.logInfo(`V2 - Created API mapping '${domain.basePath}' for '${domain.givenDomainName}'`);
Expand Down Expand Up @@ -171,20 +165,14 @@ class APIGatewayV2Wrapper extends APIGatewayBase {
* @param domain: DomainConfig
*/
public async updateBasePathMapping(domain: DomainConfig): Promise<void> {
let stage = domain.stage;
if (domain.apiType === Globals.apiTypes.http) {
// find a better way how to implement custom stage for the HTTP API type
stage = Globals.defaultStage;
}

try {
await this.apiGateway.send(
new UpdateApiMappingCommand({
ApiId: domain.apiId,
ApiMappingId: domain.apiMapping.apiMappingId,
ApiMappingKey: domain.basePath,
DomainName: domain.givenDomainName,
Stage: stage,
Stage: domain.stage,
})
);
Logging.logInfo(`V2 - Updated API mapping to '${domain.basePath}' for '${domain.givenDomainName}'`);
Expand Down
1 change: 0 additions & 1 deletion src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default class Globals {

public static defaultRegion = "us-east-1";
public static defaultBasePath = "(none)";
public static defaultStage = "$default";

// https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html
public static reservedBasePaths = ["ping", "sping"];
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class ServerlessCustomDomain {
}

// Remove all special characters
const safeStage = domain.stage.replace(/[^a-zA-Z0-9]/g, "");
const safeStage = domain.stage.replace(/[^a-zA-Z\d]/g, "");
service.provider.compiledCloudFormationTemplate.Outputs[domainNameOutputKey] = {
Value: domain.givenDomainName,
Export: {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/aws/api-gateway-v1-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe("API Gateway V1 wrapper checks", () => {
basePath: dc.basePath,
domainName: dc.givenDomainName,
restApiId: dc.apiId,
stage: dc.baseStage,
stage: dc.stage,
}
const commandCalls = APIGatewayMock.commandCalls(CreateBasePathMappingCommand, expectedParams, true);

Expand Down
6 changes: 3 additions & 3 deletions test/unit-tests/aws/api-gateway-v2-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe("API Gateway V2 wrapper checks", () => {
ApiMappingKey: dc.basePath,
DomainName: dc.givenDomainName,
ApiId: dc.apiId,
Stage: dc.baseStage,
Stage: dc.stage,
}
const commandCalls = APIGatewayMock.commandCalls(CreateApiMappingCommand, expectedParams, true);

Expand All @@ -336,7 +336,7 @@ describe("API Gateway V2 wrapper checks", () => {
ApiMappingKey: dc.basePath,
DomainName: dc.givenDomainName,
ApiId: dc.apiId,
Stage: Globals.defaultStage,
Stage: dc.stage,
}
const commandCalls = APIGatewayMock.commandCalls(CreateApiMappingCommand, expectedParams, true);

Expand Down Expand Up @@ -472,7 +472,7 @@ describe("API Gateway V2 wrapper checks", () => {
ApiMappingId: dc.apiMapping.apiMappingId,
ApiMappingKey: dc.basePath,
DomainName: dc.givenDomainName,
Stage: Globals.defaultStage
Stage: dc.stage
}
const commandCalls = APIGatewayMock.commandCalls(UpdateApiMappingCommand, expectedParams, true);

Expand Down

0 comments on commit 6d36152

Please sign in to comment.