Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Domain and Distribution to Stack Outputs #47

Merged
merged 5 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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