Skip to content

Commit

Permalink
Merge pull request #178 from attila/fix/custom-restapiid
Browse files Browse the repository at this point in the history
Use existing API id only when defined
  • Loading branch information
jconstance-amplify committed Jan 11, 2019
2 parents c019c7e + b439014 commit a6d8ea2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -314,7 +314,7 @@ class ServerlessCustomDomain {
let apiGatewayRef = { Ref: 'ApiGatewayRestApi' };

// If user has specified an existing API Gateway API, then attach to that
if (service.provider.apiGateway) {
if (service.provider.apiGateway && service.provider.apiGateway.restApiId) {
this.serverless.cli.log(`Mapping custom domain to existing API ${service.provider.apiGateway.restApiId}.`);
apiGatewayRef = service.provider.apiGateway.restApiId;
}
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": "2.6.10",
"version": "2.6.11",
"engines": {
"node": ">=4.0"
},
Expand Down
18 changes: 18 additions & 0 deletions test/unit-tests/index.test.js
Expand Up @@ -163,6 +163,24 @@ describe('Custom Domain Plugin', () => {
const cf = noStagePlugin.serverless.service.provider.compiledCloudFormationTemplate.Resources;
expect(cf.pathmapping.Properties.Stage).to.equal('providerStage');
});

it('references the id of the API being created', () => {
plugin.addResources(deploymentId);
const cf = plugin.serverless.service.provider.compiledCloudFormationTemplate
.Resources;
expect(cf.pathmapping.Properties.RestApiId).to.deep.equal({ Ref: 'ApiGatewayRestApi' });
});

it('uses existing API id when defined in provider data', () => {
const apiIdExistingPlugin = constructPlugin('test_basepath', null, true, true);
apiIdExistingPlugin.serverless.service.provider.apiGateway = {
restApiId: 'some-id',
};
apiIdExistingPlugin.addResources(deploymentId);
const cf = apiIdExistingPlugin.serverless.service.provider.compiledCloudFormationTemplate
.Resources;
expect(cf.pathmapping.Properties.RestApiId).to.equal('some-id');
});
});

describe('Create a New Domain Name', () => {
Expand Down

0 comments on commit a6d8ea2

Please sign in to comment.