@@ -25,25 +25,39 @@ export class StacksCloud extends Stack {
25
25
if ( ! app . url )
26
26
throw new Error ( './config app.url is not defined' )
27
27
28
+ const domainName = app . url
29
+
28
30
const zone = new route53 . PublicHostedZone ( this , 'HostedZone' , {
29
- zoneName : 'stacksjs.com' ,
31
+ zoneName : domainName ,
30
32
} )
31
33
32
34
const certificate = new acm . Certificate ( this , 'WebsiteCertificate' , {
33
- domainName : 'stacksjs.com' ,
34
- validation : acm . CertificateValidation . fromDns ( zone ) , // Use DNS validation
35
+ domainName,
36
+ validation : acm . CertificateValidation . fromDns ( zone ) ,
37
+ } )
38
+
39
+ const docsCertificate = new acm . Certificate ( this , 'DocsCertificate' , {
40
+ domainName : `${ app . subdomains . docs } .${ domainName } ` ,
41
+ validation : acm . CertificateValidation . fromDns ( zone ) ,
35
42
} )
36
43
37
44
const webBucket = new s3 . Bucket ( this , 'WebBucket' , {
38
- bucketName : 'stacksjs.com-23123123424324' ,
45
+ bucketName : `${ domainName } -${ app . env } ` ,
46
+ versioned : true ,
47
+ removalPolicy : RemovalPolicy . DESTROY ,
48
+ autoDeleteObjects : true ,
49
+ } )
50
+
51
+ const docsBucket = new s3 . Bucket ( this , 'DocsBucket' , {
52
+ bucketName : `docs.${ domainName } -${ app . env } ` ,
39
53
versioned : true ,
40
54
removalPolicy : RemovalPolicy . DESTROY ,
41
55
autoDeleteObjects : true ,
42
56
} )
43
57
44
58
// Create an S3 bucket for CloudFront access logs
45
59
const logBucket = new s3 . Bucket ( this , 'LogBucket' , {
46
- bucketName : 'stacksjs.com34534545 -logs' ,
60
+ bucketName : ` ${ domainName } -logs- ${ app . env } ` ,
47
61
removalPolicy : RemovalPolicy . DESTROY ,
48
62
autoDeleteObjects : true ,
49
63
objectOwnership : s3 . ObjectOwnership . BUCKET_OWNER_PREFERRED ,
@@ -69,11 +83,11 @@ export class StacksCloud extends Stack {
69
83
70
84
const originAccessIdentity = new cloudfront . OriginAccessIdentity ( this , 'OAI' )
71
85
72
- // // create a CDN to deploy your website
86
+ // create a CDN to deploy your website
73
87
const distribution = new cloudfront . Distribution ( this , 'Distribution' , {
74
- domainNames : [ 'stacksjs.com' ] ,
88
+ domainNames : [ domainName ] ,
75
89
defaultRootObject : 'index.html' ,
76
- comment : `CDN for ${ app . name } ` ,
90
+ comment : `CDN for ${ app . url } ` ,
77
91
certificate,
78
92
// originShieldEnabled: true,
79
93
enableLogging : true ,
@@ -112,24 +126,71 @@ export class StacksCloud extends Stack {
112
126
// ],
113
127
} )
114
128
129
+ const docsDistribution = new cloudfront . Distribution ( this , 'DocsDistribution' , {
130
+ domainNames : [ `${ app . subdomains . docs } .${ app . url } ` ] ,
131
+ defaultRootObject : 'index.html' ,
132
+ comment : `CDN for ${ app . subdomains . docs } .${ app . url } ` ,
133
+ certificate : docsCertificate ,
134
+ // originShieldEnabled: true,
135
+ enableLogging : true ,
136
+ logBucket,
137
+ httpVersion : cloudfront . HttpVersion . HTTP2_AND_3 ,
138
+ priceClass : cloudfront . PriceClass . PRICE_CLASS_ALL ,
139
+ enabled : true ,
140
+ minimumProtocolVersion : cloudfront . SecurityPolicyProtocol . TLS_V1_2_2021 ,
141
+ webAclId : webAcl . attrArn ,
142
+ enableIpv6 : true ,
143
+
144
+ defaultBehavior : {
145
+ origin : new origins . S3Origin ( docsBucket , {
146
+ originAccessIdentity,
147
+ } ) ,
148
+ compress : true ,
149
+ allowedMethods : cloudfront . AllowedMethods . ALLOW_GET_HEAD ,
150
+ cachedMethods : cloudfront . CachedMethods . CACHE_GET_HEAD ,
151
+ viewerProtocolPolicy : cloudfront . ViewerProtocolPolicy . REDIRECT_TO_HTTPS ,
152
+ cachePolicy : cloudfront . CachePolicy . CACHING_OPTIMIZED ,
153
+ } ,
154
+
155
+ // errorResponses: [
156
+ // {
157
+ // httpStatus: 403,
158
+ // responsePagePath: '/index.html',
159
+ // responseHttpStatus: 200,
160
+ // ttl: cdk.Duration.minutes(0),
161
+ // },
162
+ // {
163
+ // httpStatus: 404,
164
+ // responsePagePath: '/index.html',
165
+ // responseHttpStatus: 200,
166
+ // ttl: cdk.Duration.minutes(0),
167
+ // },
168
+ // ],
169
+ } )
170
+
115
171
// Create a Route53 record pointing to the CloudFront distribution
116
172
// eslint-disable-next-line no-new
117
173
new route53 . ARecord ( this , 'AliasRecord' , {
118
- recordName : 'stacksjs.com' ,
174
+ recordName : domainName ,
175
+ zone,
176
+ target : route53 . RecordTarget . fromAlias ( new targets . CloudFrontTarget ( distribution ) ) ,
177
+ } )
178
+
179
+ // Create a Route53 record pointing to the Docs CloudFront distribution
180
+ // eslint-disable-next-line no-new
181
+ new route53 . ARecord ( this , 'DocsAliasRecord' , {
182
+ recordName : `${ app . subdomains . docs } .${ domainName } ` ,
119
183
zone,
120
- // recordName: domainName,
121
184
target : route53 . RecordTarget . fromAlias ( new targets . CloudFrontTarget ( distribution ) ) ,
122
185
} )
123
186
124
187
// eslint-disable-next-line no-new
125
188
new route53 . CnameRecord ( this , 'WwwCnameRecord' , {
126
189
zone,
127
190
recordName : 'www' ,
128
- domainName : 'stacksjs.com' ,
191
+ domainName,
129
192
} )
130
193
131
- // housekeeping for uploading the data in the bucket
132
-
133
194
// eslint-disable-next-line no-new
134
195
new s3deploy . BucketDeployment ( this , 'DeployWebsite' , {
135
196
sources : [ s3deploy . Source . asset ( '../../../storage/public' ) ] ,
@@ -138,13 +199,28 @@ export class StacksCloud extends Stack {
138
199
distributionPaths : [ '/*' ] ,
139
200
} )
140
201
202
+ // eslint-disable-next-line no-new
203
+ new s3deploy . BucketDeployment ( this , 'DeployDocs' , {
204
+ sources : [ s3deploy . Source . asset ( '../../../storage/app/docs' ) ] ,
205
+ destinationBucket : webBucket ,
206
+ distribution,
207
+ distributionPaths : [ '/*' ] ,
208
+ } )
209
+
141
210
// Prints out the web endpoint to the terminal
142
211
// eslint-disable-next-line no-new
143
212
new Output ( this , 'AppUrl' , {
144
- value : ' https://stacksjs.com' ,
213
+ value : ` https://${ domainName } ` ,
145
214
description : 'The URL of the deployed application' ,
146
215
} )
147
216
217
+ // Prints out the web endpoint to the terminal
218
+ // eslint-disable-next-line no-new
219
+ new Output ( this , 'DocsUrl' , {
220
+ value : `https://${ app . subdomains . docs } .${ app . url } ` ,
221
+ description : 'The URL of the deployed documentation' ,
222
+ } )
223
+
148
224
// Prints out the web endpoint to the terminal
149
225
// eslint-disable-next-line no-new
150
226
new Output ( this , 'VanityUrl' , {
0 commit comments