Skip to content

Commit

Permalink
Merge pull request #47 from amplify-education/add_outputs
Browse files Browse the repository at this point in the history
Add Domain and Distribution to Stack Outputs
  • Loading branch information
majones-amplify committed Nov 6, 2017
2 parents 9e607c4 + 2e077d5 commit 8e61872
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
});
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "1.1.16",
"version": "1.1.17",
"engines": {
"node": ">=4.0"
},
Expand Down
13 changes: 10 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 8e61872

Please sign in to comment.