From ac0ee6f1415c81b6daa7608995363dc4b411aec0 Mon Sep 17 00:00:00 2001 From: Malcolm Jones Date: Mon, 6 Nov 2017 11:29:24 -0500 Subject: [PATCH 1/5] Add Domain and Distribution to Stack Output --- index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bd96c80c..93f70266 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 */ From a3af9bee8834af483eaa8b5af16f420df67ceebf Mon Sep 17 00:00:00 2001 From: Malcolm Jones Date: Mon, 6 Nov 2017 11:29:49 -0500 Subject: [PATCH 2/5] Update Tests --- test/index.test.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 0969b035..36ae92a2 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 () => { From a49614a1605fe9834199969e732cc039a249a9a0 Mon Sep 17 00:00:00 2001 From: Malcolm Jones Date: Mon, 6 Nov 2017 11:30:39 -0500 Subject: [PATCH 3/5] Version Bump --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ae896b7a..81023695 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" }, @@ -43,6 +43,7 @@ }, "dependencies": { "aws-sdk": "^2.2.33", - "chalk": "^2.0.1" + "chalk": "^2.0.1", + "node": "^9.0.0" } } From 0a13a068c508abe2183a7fe2fcd079fa09872239 Mon Sep 17 00:00:00 2001 From: Malcolm Jones Date: Mon, 6 Nov 2017 11:34:41 -0500 Subject: [PATCH 4/5] Remove unneeded package.json changes --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 81023695..f2432bc4 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ }, "dependencies": { "aws-sdk": "^2.2.33", - "chalk": "^2.0.1", - "node": "^9.0.0" + "chalk": "^2.0.1" } } From 2e077d57bdae25038025275517f8ae28dec2cf1d Mon Sep 17 00:00:00 2001 From: Malcolm Jones Date: Mon, 6 Nov 2017 11:41:27 -0500 Subject: [PATCH 5/5] Fix linting issues --- index.js | 4 ++-- test/index.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 93f70266..c292d9a2 100644 --- a/index.js +++ b/index.js @@ -199,10 +199,10 @@ class ServerlessCustomDomain { service.provider.compiledCloudFormationTemplate.Outputs = {}; } service.provider.compiledCloudFormationTemplate.Outputs.DomainName = { - Value: data.domainName + Value: data.domainName, }; service.provider.compiledCloudFormationTemplate.Outputs.DistributionDomainName = { - Value: data.distributionDomainName + Value: data.distributionDomainName, }; } diff --git a/test/index.test.js b/test/index.test.js index 36ae92a2..1299e0d6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -92,7 +92,7 @@ describe('Custom Domain Plugin', () => { }); it('Add Domain Name and Distribution Name to stack output', () => { - plugin.addOutputs( {'domainName': 'fake_domain', 'distributionDomainName' : 'fake_dist_name'} ); + plugin.addOutputs({ domainName: 'fake_domain', distributionDomainName: 'fake_dist_name' }); const cfTemplat = plugin.serverless.service.provider.compiledCloudFormationTemplate.Outputs; expect(cfTemplat).to.not.equal(undefined); }); @@ -262,7 +262,7 @@ describe('Custom Domain Plugin', () => { describe('Hook Methods', () => { it('setupBasePathMapping', async () => { AWS.mock('APIGateway', 'getDomainName', (params, callback) => { - callback(null, { 'domainName': 'fake_domain', 'distributionDomainName': 'fake_dist_name'}); + callback(null, { domainName: 'fake_domain', distributionDomainName: 'fake_dist_name' }); }); const plugin = constructPlugin('', null, true, true); plugin.apigateway = new aws.APIGateway();