-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdomain-stack.ts
31 lines (23 loc) · 1 KB
/
domain-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as cdk from "aws-cdk-lib";
import * as route53 from "aws-cdk-lib/aws-route53";
import { Construct } from "constructs";
import { Environment } from "./environment";
import { parseDomain, ParseResultType } from "parse-domain";
type DomainStackProps = cdk.StackProps & { environment: Environment };
export class DomainStack extends cdk.Stack {
readonly domainName: string;
readonly subdomainName: string;
readonly hostedZone: route53.IHostedZone;
constructor(scope: Construct, id: string, props: DomainStackProps) {
super(scope, id, props);
let parseResult = parseDomain(props.environment.subdomainName);
if (parseResult.type !== ParseResultType.Listed)
throw Error("Invalid subdomain name");
let { domain, topLevelDomains } = parseResult;
this.domainName = `${domain}.${topLevelDomains.join(".")}`;
this.subdomainName = props.environment.subdomainName;
this.hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
domainName: this.domainName,
});
}
}