diff --git a/index.js b/index.js index bd96c80c..c292d9a2 100644 --- a/index.js +++ b/index.js @@ -84,9 +84,10 @@ class ServerlessCustomDomain { setUpBasePathMapping() { this.initializeVariables(); - return this.getDomain().then(() => { + return this.getDomain().then((data) => { const deploymentId = this.getDeploymentId(); this.addResources(deploymentId); + this.addOutputs(data); }).catch((err) => { throw new Error(`${err} Try running sls create_domain first.`); }); @@ -189,6 +190,22 @@ class ServerlessCustomDomain { service.provider.compiledCloudFormationTemplate.Resources.pathmapping = pathmapping; } + /** + * Adds the domain name and distribution domain name to the CloudFormation outputs + */ + addOutputs(data) { + const service = this.serverless.service; + if (!service.provider.compiledCloudFormationTemplate.Outputs) { + service.provider.compiledCloudFormationTemplate.Outputs = {}; + } + service.provider.compiledCloudFormationTemplate.Outputs.DomainName = { + Value: data.domainName, + }; + service.provider.compiledCloudFormationTemplate.Outputs.DistributionDomainName = { + Value: data.distributionDomainName, + }; + } + /* * Obtains the certification arn */ diff --git a/package.json b/package.json index ae896b7a..f2432bc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-domain-manager", - "version": "1.1.16", + "version": "1.1.17", "engines": { "node": ">=4.0" }, diff --git a/test/index.test.js b/test/index.test.js index 0969b035..1299e0d6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -91,6 +91,12 @@ describe('Custom Domain Plugin', () => { expect(cfTemplat).to.not.equal(undefined); }); + it('Add Domain Name and Distribution Name to stack output', () => { + plugin.addOutputs({ domainName: 'fake_domain', distributionDomainName: 'fake_dist_name' }); + const cfTemplat = plugin.serverless.service.provider.compiledCloudFormationTemplate.Outputs; + expect(cfTemplat).to.not.equal(undefined); + }); + it('(none) is added if empty basepath is given', () => { const emptyPlugin = constructPlugin('', null, true, true); emptyPlugin.addResources(deploymentId); @@ -256,15 +262,16 @@ describe('Custom Domain Plugin', () => { describe('Hook Methods', () => { it('setupBasePathMapping', async () => { AWS.mock('APIGateway', 'getDomainName', (params, callback) => { - callback(null, params); + callback(null, { domainName: 'fake_domain', distributionDomainName: 'fake_dist_name' }); }); const plugin = constructPlugin('', null, true, true); plugin.apigateway = new aws.APIGateway(); plugin.setGivenDomainName(plugin.serverless.service.custom.customDomain.domainName); await plugin.setUpBasePathMapping(); - const cfTemplat = plugin.serverless.service.provider.compiledCloudFormationTemplate.Resources; - expect(cfTemplat).to.not.equal(undefined); + const cfTemplat = plugin.serverless.service.provider.compiledCloudFormationTemplate; + expect(cfTemplat.Resources).to.not.equal(undefined); + expect(cfTemplat.Outputs).to.not.equal(undefined); }); it('deleteDomain', async () => {