@@ -37,6 +37,7 @@ export class StacksCloud extends Stack {
37
37
websiteSource : string
38
38
privateSource : string
39
39
zone ! : route53 . IHostedZone
40
+ redirectZones : route53 . IHostedZone [ ] = [ ]
40
41
ec2Instance ! : ec2 . Instance
41
42
storage ! : {
42
43
publicBucket : s3 . Bucket
@@ -250,9 +251,15 @@ export class StacksCloud extends Stack {
250
251
manageZone ( ) {
251
252
// lets see if the zone already exists
252
253
try {
253
- this . zone = route53 . PublicHostedZone . fromLookup ( this , 'HostedZone ' , {
254
+ this . zone = route53 . PublicHostedZone . fromLookup ( this , 'AppUrlHostedZone ' , {
254
255
domainName : this . domain ,
255
256
} )
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
+ } )
256
263
}
257
264
// if not, lets create it
258
265
catch ( error ) {
@@ -277,6 +284,23 @@ export class StacksCloud extends Stack {
277
284
autoDeleteObjects : true ,
278
285
} )
279
286
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
+
280
304
const privateBucket = new s3 . Bucket ( this , 'PrivateBucket' , {
281
305
bucketName : `${ this . domain } -private-${ config . app . env } ` ,
282
306
versioned : true ,
@@ -533,6 +557,7 @@ export class StacksCloud extends Stack {
533
557
534
558
new Output ( this , 'JumpBoxInstanceId' , {
535
559
value : this . ec2Instance . instanceId ,
560
+ description : 'The ID of the EC2 instance that can be used to SSH into the Stacks Cloud.' ,
536
561
} )
537
562
538
563
// if docsPrefix is not set, then we know we are in docsMode and the documentation lives at the root of the domain
0 commit comments