Skip to content

Commit 6b173d4

Browse files
author
Aleksander Dikanski
committed
Add support for domain manager plugin
1 parent b65e258 commit 6b173d4

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

lib/stackops/apiGateway.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
188188
aliasResources.push({ ApiGatewayStage: stageResource });
189189
}
190190

191+
const baseMapping = _.assign({}, _.pickBy(stageStack.Resources, ['Type', 'AWS::ApiGateway::BasePathMapping']));
192+
if (!_.isEmpty(baseMapping)) {
193+
const baseMappingName = _.keys(baseMapping)[0];
194+
const obj = baseMapping[baseMappingName];
195+
196+
delete obj.Properties.StageName;
197+
obj.Properties.RestApiId = { 'Fn::ImportValue': `${stackName}-ApiGatewayRestApi`};
198+
199+
aliasResources.push(baseMapping);
200+
delete stageStack.Resources[baseMappingName];
201+
}
202+
191203
// Fetch lambda permissions, methods and resources. These have to be updated later to allow the aliased functions.
192204
const apiLambdaPermissions =
193205
_.assign({},

test/data/auth-stack-2.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,15 @@
464464
}
465465
}
466466
},
467+
"pathmapping": {
468+
"Type": "AWS::ApiGateway::BasePathMapping",
469+
"Properties": {
470+
"BasePath": "(none)",
471+
"DomainName": "example.com",
472+
"RestApiId": { "Fn::ImportValue": "ApiGatewayRestApi" },
473+
"Stage": "test"
474+
}
475+
},
467476
"TestauthLambdaPermissionApiGateway": {
468477
"Type": "AWS::Lambda::Permission",
469478
"Properties": {

test/stackops/apiGateway.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ describe('API Gateway', () => {
713713
.to.have.a.nested.property("Resources.ApiGatewayMethodFunc2Get.DependsOn")
714714
.that.equals("PseudoParamCustomAuthApiGatewayAuthorizermyAlias"),
715715
expect(template)
716-
.to.have.a.nested.property('Resources.PseudoParamCustomAuthApiGatewayAuthorizermyAlias.Properties.AuthorizerUri')
716+
.to.have.a.nested.property('Resources.PseudoParamCustomAuthApiGatewayAuthorizermyAlias.Properties.AuthorizerUri')
717717
.that.deep.equals({
718718
"Fn::Join": [
719719
"",
@@ -733,6 +733,29 @@ describe('API Gateway', () => {
733733

734734
});
735735

736+
it('should move base mappings to alias stack', () => {
737+
stackTemplate = _.cloneDeep(require('../data/auth-stack-2.json'));
738+
const template = serverless.service.provider.compiledCloudFormationTemplate = stackTemplate;
739+
const compiledAliasTemplate = serverless.service.provider.compiledCloudFormationAliasTemplate = aliasTemplate;
740+
return expect(awsAlias.aliasHandleApiGateway({}, [], {})).to.be.fulfilled
741+
.then(()=> BbPromise.all([
742+
expect(template)
743+
.to.not.have.a.nested.property('Resources.pathmapping'),
744+
expect(aliasTemplate)
745+
.to.have.a.nested.property('Resources.pathmapping')
746+
.that.deep.equals({
747+
Type: 'AWS::ApiGateway::BasePathMapping',
748+
Properties: {
749+
BasePath: '(none)',
750+
DomainName: 'example.com',
751+
RestApiId: { 'Fn::ImportValue': 'testService-myStage-ApiGatewayRestApi' },
752+
Stage: 'test'
753+
}
754+
})
755+
]));
756+
757+
});
758+
736759
it('should transform string dependencies and references to authorizers', () => {
737760
const template = serverless.service.provider.compiledCloudFormationTemplate = stackTemplate;
738761
serverless.service.provider.compiledCloudFormationAliasTemplate = aliasTemplate;

0 commit comments

Comments
 (0)