@@ -20,14 +20,14 @@ import {
20
20
} from 'aws-cdk-lib'
21
21
import { hasFiles } from '@stacksjs/storage'
22
22
import { path as p } from '@stacksjs/path'
23
- import { app , cloud , docs } from '@stacksjs/config'
23
+ import { config } from '@stacksjs/config'
24
24
import { log } from '@stacksjs/logging'
25
25
import { env } from '@stacksjs/env'
26
26
import { EnvKey } from '~/storage/framework/stacks/env'
27
27
28
28
export class StacksCloud extends Stack {
29
- domain : string = ''
30
- apiPath : string
29
+ domain : string
30
+ apiPrefix : string
31
31
docsPath ?: string
32
32
apiVanityUrl : string
33
33
vanityUrl : string
@@ -51,14 +51,14 @@ export class StacksCloud extends Stack {
51
51
constructor ( scope : Construct , id : string , props ?: StackProps ) {
52
52
super ( scope , id , props )
53
53
54
- if ( ! app . url )
55
- throw new Error ( 'Your ./config app.url needs to be defined in order to deploy. You may need to adjust the APP_URL inside your .env file.' )
54
+ if ( ! config . app . url )
55
+ throw new Error ( 'Your ./config config. app.url needs to be defined in order to deploy. You may need to adjust the APP_URL inside your .env file.' )
56
56
57
- this . domain = app . url || 'stacksjs.com'
58
- this . apiPath = 'api'
59
- this . docsPath = app . docMode ? undefined : docs . base
57
+ this . domain = config . app . url || 'stacksjs.com'
58
+ this . apiPrefix = config . api . prefix || 'api'
59
+ this . docsPath = config . app . docMode ? undefined : config . docs . base
60
60
this . docsSource = '../../../storage/framework/docs'
61
- this . websiteSource = app . docMode ? this . docsSource : '../../../storage/public'
61
+ this . websiteSource = config . app . docMode ? this . docsSource : '../../../storage/public'
62
62
this . privateSource = '../../../storage/private'
63
63
this . apiVanityUrl = ''
64
64
@@ -84,7 +84,7 @@ export class StacksCloud extends Stack {
84
84
}
85
85
86
86
shouldDeployApi ( ) {
87
- return cloud . deploy ?. api
87
+ return config . cloud . deploy ?. api
88
88
}
89
89
90
90
setApiCachePolicy ( ) {
@@ -94,7 +94,7 @@ export class StacksCloud extends Stack {
94
94
this . apiCachePolicy = new cloudfront . CachePolicy ( this , 'StacksApiCachePolicy' , {
95
95
comment : 'Stacks API Cache Policy' ,
96
96
cachePolicyName : 'StacksApiCachePolicy' ,
97
- // minTtl: cloud.cdn?.minTtl ? Duration.seconds(cloud.cdn.minTtl) : undefined,
97
+ // minTtl: config. cloud.cdn?.minTtl ? Duration.seconds(config. cloud.cdn.minTtl) : undefined,
98
98
defaultTtl : Duration . seconds ( 0 ) ,
99
99
cookieBehavior : cloudfront . CacheCookieBehavior . none ( ) ,
100
100
headerBehavior : cloudfront . CacheHeaderBehavior . allowList ( 'Accept' , 'x-api-key' , 'Authorization' ) ,
@@ -117,7 +117,7 @@ export class StacksCloud extends Stack {
117
117
keysToRemove . forEach ( key => delete env [ key as EnvKey ] )
118
118
119
119
const secrets = new secretsmanager . Secret ( this , 'StacksSecrets' , {
120
- secretName : `${ app . name } -${ app . env } -secrets` ,
120
+ secretName : `${ config . app . name } -${ config . app . env } -secrets` ,
121
121
description : 'Secrets for the Stacks application' ,
122
122
generateSecretString : {
123
123
secretStringTemplate : JSON . stringify ( env ) ,
@@ -190,14 +190,14 @@ export class StacksCloud extends Stack {
190
190
return cloudfront . CacheCookieBehavior . none ( )
191
191
case 'allowList' :
192
192
// If you have a list of cookies, replace `myCookie` with your cookie
193
- return cloudfront . CacheCookieBehavior . allowList ( ...cloud . cdn ?. allowList . cookies || [ ] )
193
+ return cloudfront . CacheCookieBehavior . allowList ( ...config . cloud . cdn ?. allowList . cookies || [ ] )
194
194
default :
195
195
return undefined
196
196
}
197
197
}
198
198
199
199
allowedMethods ( ) : cloudfront . AllowedMethods {
200
- switch ( cloud . cdn ?. allowedMethods ) {
200
+ switch ( config . cloud . cdn ?. allowedMethods ) {
201
201
case 'ALL' :
202
202
return cloudfront . AllowedMethods . ALLOW_ALL
203
203
case 'GET_HEAD' :
@@ -210,7 +210,7 @@ export class StacksCloud extends Stack {
210
210
}
211
211
212
212
cachedMethods ( ) : cloudfront . CachedMethods {
213
- switch ( cloud . cdn ?. cachedMethods ) {
213
+ switch ( config . cloud . cdn ?. cachedMethods ) {
214
214
case 'GET_HEAD' :
215
215
return cloudfront . CachedMethods . CACHE_GET_HEAD
216
216
case 'GET_HEAD_OPTIONS' :
@@ -236,31 +236,34 @@ export class StacksCloud extends Stack {
236
236
}
237
237
238
238
manageZone ( ) {
239
- console . log ( 'Creating hosted zone' , this . domain )
240
239
return new route53 . PublicHostedZone ( this , 'HostedZone' , {
241
- zoneName : 'stacksjs.com' ,
240
+ zoneName : this . domain ,
242
241
} )
243
242
}
244
243
245
244
manageCertificate ( ) {
246
- log . error ( `Creating certificate for ${ this . domain } in ${ app . env } environment` )
245
+ log . error ( `Creating certificate for ${ this . domain } in ${ config . app . env } environment` )
246
+ console . log ( 'this domain' , this . domain )
247
+ console . log ( 'this domain type' , typeof this . domain )
248
+
249
+ const domainName = typeof this . domain === 'object' ? this . domain . url : this . domain
247
250
248
251
return new acm . Certificate ( this , 'WebsiteCertificate' , {
249
- domainName : this . domain ,
252
+ domainName,
250
253
validation : acm . CertificateValidation . fromDns ( this . zone ) ,
251
254
} )
252
255
}
253
256
254
257
manageStorage ( ) {
255
258
const publicBucket = new s3 . Bucket ( this , 'PublicBucket' , {
256
- bucketName : `${ this . domain } -${ app . env } ` ,
259
+ bucketName : `${ this . domain } -${ config . app . env } ` ,
257
260
versioned : true ,
258
261
removalPolicy : RemovalPolicy . DESTROY ,
259
262
autoDeleteObjects : true ,
260
263
} )
261
264
262
265
const privateBucket = new s3 . Bucket ( this , 'PrivateBucket' , {
263
- bucketName : `${ this . domain } -private-${ app . env } ` ,
266
+ bucketName : `${ this . domain } -private-${ config . app . env } ` ,
264
267
versioned : true ,
265
268
removalPolicy : RemovalPolicy . DESTROY ,
266
269
autoDeleteObjects : true ,
@@ -269,9 +272,9 @@ export class StacksCloud extends Stack {
269
272
// Create an S3 bucket for CloudFront access logs
270
273
let logBucket : s3 . Bucket | undefined
271
274
272
- if ( cloud . cdn ?. enableLogging ) {
275
+ if ( config . cloud . cdn ?. enableLogging ) {
273
276
logBucket = new s3 . Bucket ( this , 'LogBucket' , {
274
- bucketName : `${ this . domain } -logs-${ app . env } ` ,
277
+ bucketName : `${ this . domain } -logs-${ config . app . env } ` ,
275
278
removalPolicy : RemovalPolicy . DESTROY ,
276
279
autoDeleteObjects : true ,
277
280
objectOwnership : s3 . ObjectOwnership . BUCKET_OWNER_PREFERRED ,
@@ -304,19 +307,19 @@ export class StacksCloud extends Stack {
304
307
const cdnCachePolicy = new cloudfront . CachePolicy ( this , 'cdnCachePolicy' , {
305
308
comment : 'Stacks CDN Cache Policy' ,
306
309
cachePolicyName : 'cdnCachePolicy' ,
307
- minTtl : cloud . cdn ?. minTtl ? Duration . seconds ( cloud . cdn . minTtl ) : undefined ,
308
- defaultTtl : cloud . cdn ?. defaultTtl ? Duration . seconds ( cloud . cdn . defaultTtl ) : undefined ,
309
- maxTtl : cloud . cdn ?. maxTtl ? Duration . seconds ( cloud . cdn . maxTtl ) : undefined ,
310
- cookieBehavior : this . getCookieBehavior ( cloud . cdn ?. cookieBehavior ) ,
310
+ minTtl : config . cloud . cdn ?. minTtl ? Duration . seconds ( config . cloud . cdn . minTtl ) : undefined ,
311
+ defaultTtl : config . cloud . cdn ?. defaultTtl ? Duration . seconds ( config . cloud . cdn . defaultTtl ) : undefined ,
312
+ maxTtl : config . cloud . cdn ?. maxTtl ? Duration . seconds ( config . cloud . cdn . maxTtl ) : undefined ,
313
+ cookieBehavior : this . getCookieBehavior ( config . cloud . cdn ?. cookieBehavior ) ,
311
314
} )
312
315
313
316
const cdn = new cloudfront . Distribution ( this , 'Distribution' , {
314
317
domainNames : [ this . domain ] ,
315
318
defaultRootObject : 'index.html' ,
316
- comment : `CDN for ${ app . url } ` ,
319
+ comment : `CDN for ${ config . app . url } ` ,
317
320
certificate : this . certificate ,
318
- enableLogging : cloud . cdn ?. enableLogging ,
319
- logBucket : cloud . cdn ?. enableLogging ? this . storage . logBucket : undefined ,
321
+ enableLogging : config . cloud . cdn ?. enableLogging ,
322
+ logBucket : config . cloud . cdn ?. enableLogging ? this . storage . logBucket : undefined ,
320
323
httpVersion : cloudfront . HttpVersion . HTTP2_AND_3 ,
321
324
priceClass : cloudfront . PriceClass . PRICE_CLASS_ALL ,
322
325
enabled : true ,
@@ -328,7 +331,7 @@ export class StacksCloud extends Stack {
328
331
origin : new origins . S3Origin ( this . storage . publicBucket , {
329
332
originAccessIdentity : this . originAccessIdentity ,
330
333
} ) ,
331
- compress : cloud . cdn ?. compress ,
334
+ compress : config . cloud . cdn ?. compress ,
332
335
allowedMethods : this . allowedMethods ( ) ,
333
336
cachedMethods : this . cachedMethods ( ) ,
334
337
viewerProtocolPolicy : cloudfront . ViewerProtocolPolicy . REDIRECT_TO_HTTPS ,
@@ -352,7 +355,7 @@ export class StacksCloud extends Stack {
352
355
353
356
// if docMode is used, we don't need to add a behavior for the docs
354
357
// because the docs will be the root of the site
355
- if ( this . shouldDeployDocs ( ) && ! app . docMode ) {
358
+ if ( this . shouldDeployDocs ( ) && ! config . app . docMode ) {
356
359
behaviorOptions = {
357
360
...this . docsBehaviorOptions ( ) ,
358
361
...behaviorOptions ,
@@ -394,8 +397,8 @@ export class StacksCloud extends Stack {
394
397
originPath : '/docs' ,
395
398
} ) ,
396
399
compress : true ,
397
- allowedMethods : this . allowedMethodsFromString ( cloud . cdn ?. allowedMethods ) ,
398
- cachedMethods : this . cachedMethodsFromString ( cloud . cdn ?. cachedMethods ) ,
400
+ allowedMethods : this . allowedMethodsFromString ( config . cloud . cdn ?. allowedMethods ) ,
401
+ cachedMethods : this . cachedMethodsFromString ( config . cloud . cdn ?. cachedMethods ) ,
399
402
viewerProtocolPolicy : cloudfront . ViewerProtocolPolicy . REDIRECT_TO_HTTPS ,
400
403
cachePolicy : cloudfront . CachePolicy . CACHING_OPTIMIZED ,
401
404
} ,
@@ -405,8 +408,8 @@ export class StacksCloud extends Stack {
405
408
originPath : '/docs' ,
406
409
} ) ,
407
410
compress : true ,
408
- allowedMethods : this . allowedMethodsFromString ( cloud . cdn ?. allowedMethods ) ,
409
- cachedMethods : this . cachedMethodsFromString ( cloud . cdn ?. cachedMethods ) ,
411
+ allowedMethods : this . allowedMethodsFromString ( config . cloud . cdn ?. allowedMethods ) ,
412
+ cachedMethods : this . cachedMethodsFromString ( config . cloud . cdn ?. cachedMethods ) ,
410
413
viewerProtocolPolicy : cloudfront . ViewerProtocolPolicy . REDIRECT_TO_HTTPS ,
411
414
cachePolicy : cloudfront . CachePolicy . CACHING_OPTIMIZED ,
412
415
} ,
@@ -425,7 +428,7 @@ export class StacksCloud extends Stack {
425
428
} )
426
429
427
430
new Output ( this , 'ApiUrl' , {
428
- value : `https://${ this . domain } /${ this . apiPath } ` ,
431
+ value : `https://${ this . domain } /${ this . apiPrefix } ` ,
429
432
description : 'The URL of the deployed application' ,
430
433
} )
431
434
@@ -438,7 +441,7 @@ export class StacksCloud extends Stack {
438
441
439
442
if ( this . shouldDeployDocs ( ) ) {
440
443
new Output ( this , 'DocsUrl' , {
441
- value : `https://${ this . domain } /${ this . apiPath } ` ,
444
+ value : `https://${ this . domain } /${ this . apiPrefix } ` ,
442
445
description : 'The URL of the deployed documentation' ,
443
446
} )
444
447
}
0 commit comments