Skip to content

Commit

Permalink
Merge pull request #217 from fargito/feat/empty-static-website-params
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli authored May 31, 2022
2 parents 0ab2033 + 711f8f1 commit 1f61b86
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/constructs/aws/abstracts/StaticWebsiteAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,30 @@ export abstract class StaticWebsiteAbstract extends AwsConstruct {
) {
super(scope, id);

if (configuration.domain !== undefined && configuration.certificate === undefined) {
throw new ServerlessError(
`Invalid configuration for the static website '${id}': if a domain is configured, then a certificate ARN must be configured in the 'certificate' option.\n` +
"See https://github.com/getlift/lift/blob/master/docs/static-website.md#custom-domain",
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
}

const bucketProps = this.getBucketProps();

const bucket = new Bucket(this, "Bucket", bucketProps);

// Cast the domains to an array
this.domains = configuration.domain !== undefined ? flatten([configuration.domain]) : undefined;
// if configuration.domain is an empty array or an empty string, ignore it
this.domains =
configuration.domain !== undefined && configuration.domain.length > 0
? flatten([configuration.domain])
: undefined;
// if configuration.certificate is an empty string, ignore it
const certificate =
configuration.certificate !== undefined
configuration.certificate !== undefined && configuration.certificate !== ""
? acm.Certificate.fromCertificateArn(this, "Certificate", configuration.certificate)
: undefined;

if (this.domains !== undefined && certificate === undefined) {
throw new ServerlessError(
`Invalid configuration for the static website '${id}': if a domain is configured, then a certificate ARN must be configured in the 'certificate' option.\n` +
"See https://github.com/getlift/lift/blob/master/docs/static-website.md#custom-domain",
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
}

const functionAssociations = [
{
function: this.createResponseFunction(),
Expand Down Expand Up @@ -134,9 +139,9 @@ export abstract class StaticWebsiteAbstract extends AwsConstruct {
value: bucket.bucketName,
});
let websiteDomain: string = this.distribution.distributionDomainName;
if (configuration.domain !== undefined) {
if (this.domains !== undefined) {
// In case of multiple domains, we take the first one
websiteDomain = typeof configuration.domain === "string" ? configuration.domain : configuration.domain[0];
websiteDomain = this.domains[0];
}
this.domainOutput = new CfnOutput(this, "Domain", {
description: "Website domain name.",
Expand Down

0 comments on commit 1f61b86

Please sign in to comment.