Skip to content

Commit

Permalink
Merge pull request #320 from davidrosson/fix-cf-stack-outputs
Browse files Browse the repository at this point in the history
Fix CloudFormation stack's Outputs
  • Loading branch information
jconstance-amplify committed Apr 21, 2020
2 parents 4268e1e + 426473c commit 1a05bac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions index.ts
Expand Up @@ -63,6 +63,7 @@ class ServerlessCustomDomain {
this.hooks = {
"after:deploy:deploy": this.hookWrapper.bind(this, this.setupBasePathMapping),
"after:info:info": this.hookWrapper.bind(this, this.domainSummary),
"before:deploy:deploy": this.hookWrapper.bind(this, this.updateCloudFormationOutputs),
"before:remove:remove": this.hookWrapper.bind(this, this.removeBasePathMapping),
"create_domain:create": this.hookWrapper.bind(this, this.createDomain),
"delete_domain:delete": this.hookWrapper.bind(this, this.deleteDomain),
Expand Down Expand Up @@ -129,6 +130,14 @@ class ServerlessCustomDomain {
this.serverless.cli.log(`Custom domain ${this.givenDomainName} was deleted.`);
}

/**
* Lifecycle function to add domain info to the CloudFormation stack's Outputs
*/
public async updateCloudFormationOutputs(): Promise<void> {
const domainInfo = await this.getDomainInfo();
this.addOutputs(domainInfo);
}

/**
* Lifecycle function to create basepath mapping
* Wraps creation of basepath mapping and adds domain name info as output to cloudformation stack
Expand All @@ -144,7 +153,6 @@ class ServerlessCustomDomain {
await this.updateBasePathMapping(currentBasePath);
}
const domainInfo = await this.getDomainInfo();
this.addOutputs(domainInfo);
await this.printDomainSummary(domainInfo);
}

Expand Down Expand Up @@ -605,9 +613,12 @@ class ServerlessCustomDomain {
if (!service.provider.compiledCloudFormationTemplate.Outputs) {
service.provider.compiledCloudFormationTemplate.Outputs = {};
}
service.provider.compiledCloudFormationTemplate.Outputs.DomainName = {
service.provider.compiledCloudFormationTemplate.Outputs.DistributionDomainName = {
Value: domainInfo.domainName,
};
service.provider.compiledCloudFormationTemplate.Outputs.DomainName = {
Value: this.givenDomainName,
};
if (domainInfo.hostedZoneId) {
service.provider.compiledCloudFormationTemplate.Outputs.HostedZoneId = {
Value: domainInfo.hostedZoneId,
Expand All @@ -629,7 +640,7 @@ class ServerlessCustomDomain {
* Prints out a summary of all domain manager related info
*/
private printDomainSummary(domainInfo: DomainInfo): void {
this.serverless.cli.consoleLog(chalk.yellow.underline("Serverless Domain Manager Summary"));
this.serverless.cli.consoleLog(chalk.yellow.underline("\nServerless Domain Manager Summary"));

if (this.serverless.service.custom.customDomain.createRoute53Record !== false) {
this.serverless.cli.consoleLog(chalk.yellow("Domain Name"));
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "3.3.1",
"version": "3.3.2",
"engines": {
"node": ">=4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/index.test.ts
Expand Up @@ -170,7 +170,7 @@ describe("Custom Domain Plugin", () => {
});
});

it("Add Domain Name and HostedZoneId to stack output", () => {
it("Add Distribution Domain Name, Domain Name, and HostedZoneId to stack output", () => {
const plugin = constructPlugin({
domainName: "test_domain",
});
Expand Down

0 comments on commit 1a05bac

Please sign in to comment.