UNPKG

@stacksjs/cloud

Version:

The Stacks cloud/serverless integration & implementation.

45 lines (40 loc) 1.61 kB
import type { Construct } from 'constructs'; import type { NestedCloudProps } from '../types'; export declare interface RedirectsStackProps extends NestedCloudProps { } export declare class RedirectsStack { redirectZones: route53.IHostedZone[] = [] constructor(scope: Construct, props: RedirectsStackProps) { config.dns.redirects?.forEach((redirect: string) => { const slug = redirect .split('.') .map((part: string, index: number) => (index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1))) .join('') const hostedZone = route53.HostedZone.fromLookup(scope, 'HostedZone', { domainName: redirect, }) const redirectBucket = new s3.Bucket(scope, `RedirectBucket${slug}`, { bucketName: `${redirect}-redirect`, websiteRedirect: { hostName: props.domain, protocol: s3.RedirectProtocol.HTTPS, }, removalPolicy: RemovalPolicy.DESTROY, autoDeleteObjects: true, }) new route53.CnameRecord(scope, `RedirectRecord${slug}`, { zone: hostedZone, recordName: 'redirect', domainName: redirectBucket.bucketWebsiteDomainName, }) }) config.dns.redirects?.forEach((redirect: string) => { const slug = redirect .split('.') .map((part: string, index: number) => (index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1))) .join('') const hostedZone = route53.HostedZone.fromLookup(scope, `RedirectHostedZone${slug}`, { domainName: redirect }) this.redirectZones.push(hostedZone) }) } }