Skip to content
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ plugins:

custom:
apiCloudFront:
httpApi: true
domain: my-custom-domain.com
certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
waf: 00000000-0000-0000-0000-000000000000
Expand All @@ -62,6 +63,12 @@ custom:

### Notes

* `httpApi` can be *false* (default) or *true*. If you are using ApiGatewayV2 for your lambdas this setting must be applied

```
httpApi: true
```

* `domain` can be list, so if you want to add more domains, instead string you list multiple ones:

```
Expand Down
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@ class ServerlessApiCloudFrontPlugin {

prepareDomain(distributionConfig) {
const domain = this.getConfig('domain', null);
const httpApi = this.getConfig("httpApi", false);

if (domain !== null) {
distributionConfig.Aliases = Array.isArray(domain) ? domain : [ domain ];
} else {
delete distributionConfig.Aliases;
}
distributionConfig.Origins[0].DomainName = {
"Fn::Join": [
"",
[
{
Ref: httpApi && "HttpApi" || "ApiGatewayRestApi"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".amazonaws.com"
]
]
}
}

preparePriceClass(distributionConfig) {
Expand All @@ -99,7 +115,8 @@ class ServerlessApiCloudFrontPlugin {
}

prepareOrigins(distributionConfig) {
distributionConfig.Origins[0].OriginPath = `/${this.options.stage}`;
const httpApi = this.getConfig("httpApi", false);
distributionConfig.Origins[0].OriginPath = httpApi ? "" : `/${this.options.stage}`;
}

prepareCookies(distributionConfig) {
Expand Down
7 changes: 0 additions & 7 deletions resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ Resources:
DistributionConfig:
Origins:
- Id: ApiGateway
DomainName:
Fn::Join:
- ""
- - Ref: ApiGatewayRestApi
- ".execute-api."
- Ref: AWS::Region
- ".amazonaws.com"
CustomOriginConfig:
HTTPPort: '80'
HTTPSPort: '443'
Expand Down