Skip to content

Commit ae50fbb

Browse files
committed
chore: wip
1 parent d5127e2 commit ae50fbb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.stacks/core/cloud/src/cloud.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class StacksCloud extends Stack {
3737
websiteSource: string
3838
privateSource: string
3939
zone!: route53.IHostedZone
40+
redirectZones: route53.IHostedZone[] = []
4041
ec2Instance!: ec2.Instance
4142
storage!: {
4243
publicBucket: s3.Bucket
@@ -250,9 +251,15 @@ export class StacksCloud extends Stack {
250251
manageZone() {
251252
// lets see if the zone already exists
252253
try {
253-
this.zone = route53.PublicHostedZone.fromLookup(this, 'HostedZone', {
254+
this.zone = route53.PublicHostedZone.fromLookup(this, 'AppUrlHostedZone', {
254255
domainName: this.domain,
255256
})
257+
258+
config.dns.redirects?.forEach((redirect) => {
259+
const slug = redirect.split('.').map((part, index) => index === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1)).join('') // creates a CamelCase slug from the redirect
260+
const hostedZone = route53.HostedZone.fromLookup(this, `RedirectHostedZone${slug}`, { domainName: redirect })
261+
this.redirectZones.push(hostedZone)
262+
})
256263
}
257264
// if not, lets create it
258265
catch (error) {
@@ -277,6 +284,23 @@ export class StacksCloud extends Stack {
277284
autoDeleteObjects: true,
278285
})
279286

287+
// for each redirect, create a bucket & redirect it to the APP_URL
288+
config.dns.redirects?.forEach((redirect) => {
289+
const hostedZone = route53.HostedZone.fromLookup(this, 'HostedZone', { domainName: redirect })
290+
const redirectBucket = new s3.Bucket(this, `RedirectBucket-${redirect}`, {
291+
bucketName: `${redirect}-redirect`,
292+
websiteRedirect: {
293+
hostName: this.domain,
294+
protocol: s3.RedirectProtocol.HTTPS,
295+
},
296+
})
297+
new route53.CnameRecord(this, 'RedirectRecord', {
298+
zone: hostedZone,
299+
recordName: 'redirect',
300+
domainName: redirectBucket.bucketWebsiteDomainName,
301+
})
302+
})
303+
280304
const privateBucket = new s3.Bucket(this, 'PrivateBucket', {
281305
bucketName: `${this.domain}-private-${config.app.env}`,
282306
versioned: true,
@@ -533,6 +557,7 @@ export class StacksCloud extends Stack {
533557

534558
new Output(this, 'JumpBoxInstanceId', {
535559
value: this.ec2Instance.instanceId,
560+
description: 'The ID of the EC2 instance that can be used to SSH into the Stacks Cloud.',
536561
})
537562

538563
// if docsPrefix is not set, then we know we are in docsMode and the documentation lives at the root of the domain

bun.lockb

18.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)