Skip to content

Commit 308d2c1

Browse files
committed
chore: wip
1 parent 887edaf commit 308d2c1

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

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

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import {
2020
} from 'aws-cdk-lib'
2121
import { hasFiles } from '@stacksjs/storage'
2222
import { path as p } from '@stacksjs/path'
23-
import { app, cloud, docs } from '@stacksjs/config'
23+
import { config } from '@stacksjs/config'
2424
import { log } from '@stacksjs/logging'
2525
import { env } from '@stacksjs/env'
2626
import { EnvKey } from '~/storage/framework/stacks/env'
2727

2828
export class StacksCloud extends Stack {
29-
domain: string = ''
30-
apiPath: string
29+
domain: string
30+
apiPrefix: string
3131
docsPath?: string
3232
apiVanityUrl: string
3333
vanityUrl: string
@@ -51,14 +51,14 @@ export class StacksCloud extends Stack {
5151
constructor(scope: Construct, id: string, props?: StackProps) {
5252
super(scope, id, props)
5353

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.')
5656

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
6060
this.docsSource = '../../../storage/framework/docs'
61-
this.websiteSource = app.docMode ? this.docsSource : '../../../storage/public'
61+
this.websiteSource = config.app.docMode ? this.docsSource : '../../../storage/public'
6262
this.privateSource = '../../../storage/private'
6363
this.apiVanityUrl = ''
6464

@@ -84,7 +84,7 @@ export class StacksCloud extends Stack {
8484
}
8585

8686
shouldDeployApi() {
87-
return cloud.deploy?.api
87+
return config.cloud.deploy?.api
8888
}
8989

9090
setApiCachePolicy() {
@@ -94,7 +94,7 @@ export class StacksCloud extends Stack {
9494
this.apiCachePolicy = new cloudfront.CachePolicy(this, 'StacksApiCachePolicy', {
9595
comment: 'Stacks API Cache Policy',
9696
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,
9898
defaultTtl: Duration.seconds(0),
9999
cookieBehavior: cloudfront.CacheCookieBehavior.none(),
100100
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Accept', 'x-api-key', 'Authorization'),
@@ -117,7 +117,7 @@ export class StacksCloud extends Stack {
117117
keysToRemove.forEach(key => delete env[key as EnvKey])
118118

119119
const secrets = new secretsmanager.Secret(this, 'StacksSecrets', {
120-
secretName: `${app.name}-${app.env}-secrets`,
120+
secretName: `${config.app.name}-${config.app.env}-secrets`,
121121
description: 'Secrets for the Stacks application',
122122
generateSecretString: {
123123
secretStringTemplate: JSON.stringify(env),
@@ -190,14 +190,14 @@ export class StacksCloud extends Stack {
190190
return cloudfront.CacheCookieBehavior.none()
191191
case 'allowList':
192192
// 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 || [])
194194
default:
195195
return undefined
196196
}
197197
}
198198

199199
allowedMethods(): cloudfront.AllowedMethods {
200-
switch (cloud.cdn?.allowedMethods) {
200+
switch (config.cloud.cdn?.allowedMethods) {
201201
case 'ALL':
202202
return cloudfront.AllowedMethods.ALLOW_ALL
203203
case 'GET_HEAD':
@@ -210,7 +210,7 @@ export class StacksCloud extends Stack {
210210
}
211211

212212
cachedMethods(): cloudfront.CachedMethods {
213-
switch (cloud.cdn?.cachedMethods) {
213+
switch (config.cloud.cdn?.cachedMethods) {
214214
case 'GET_HEAD':
215215
return cloudfront.CachedMethods.CACHE_GET_HEAD
216216
case 'GET_HEAD_OPTIONS':
@@ -236,31 +236,34 @@ export class StacksCloud extends Stack {
236236
}
237237

238238
manageZone() {
239-
console.log('Creating hosted zone', this.domain)
240239
return new route53.PublicHostedZone(this, 'HostedZone', {
241-
zoneName: 'stacksjs.com',
240+
zoneName: this.domain,
242241
})
243242
}
244243

245244
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
247250

248251
return new acm.Certificate(this, 'WebsiteCertificate', {
249-
domainName: this.domain,
252+
domainName,
250253
validation: acm.CertificateValidation.fromDns(this.zone),
251254
})
252255
}
253256

254257
manageStorage() {
255258
const publicBucket = new s3.Bucket(this, 'PublicBucket', {
256-
bucketName: `${this.domain}-${app.env}`,
259+
bucketName: `${this.domain}-${config.app.env}`,
257260
versioned: true,
258261
removalPolicy: RemovalPolicy.DESTROY,
259262
autoDeleteObjects: true,
260263
})
261264

262265
const privateBucket = new s3.Bucket(this, 'PrivateBucket', {
263-
bucketName: `${this.domain}-private-${app.env}`,
266+
bucketName: `${this.domain}-private-${config.app.env}`,
264267
versioned: true,
265268
removalPolicy: RemovalPolicy.DESTROY,
266269
autoDeleteObjects: true,
@@ -269,9 +272,9 @@ export class StacksCloud extends Stack {
269272
// Create an S3 bucket for CloudFront access logs
270273
let logBucket: s3.Bucket | undefined
271274

272-
if (cloud.cdn?.enableLogging) {
275+
if (config.cloud.cdn?.enableLogging) {
273276
logBucket = new s3.Bucket(this, 'LogBucket', {
274-
bucketName: `${this.domain}-logs-${app.env}`,
277+
bucketName: `${this.domain}-logs-${config.app.env}`,
275278
removalPolicy: RemovalPolicy.DESTROY,
276279
autoDeleteObjects: true,
277280
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_PREFERRED,
@@ -304,19 +307,19 @@ export class StacksCloud extends Stack {
304307
const cdnCachePolicy = new cloudfront.CachePolicy(this, 'cdnCachePolicy', {
305308
comment: 'Stacks CDN Cache Policy',
306309
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),
311314
})
312315

313316
const cdn = new cloudfront.Distribution(this, 'Distribution', {
314317
domainNames: [this.domain],
315318
defaultRootObject: 'index.html',
316-
comment: `CDN for ${app.url}`,
319+
comment: `CDN for ${config.app.url}`,
317320
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,
320323
httpVersion: cloudfront.HttpVersion.HTTP2_AND_3,
321324
priceClass: cloudfront.PriceClass.PRICE_CLASS_ALL,
322325
enabled: true,
@@ -328,7 +331,7 @@ export class StacksCloud extends Stack {
328331
origin: new origins.S3Origin(this.storage.publicBucket, {
329332
originAccessIdentity: this.originAccessIdentity,
330333
}),
331-
compress: cloud.cdn?.compress,
334+
compress: config.cloud.cdn?.compress,
332335
allowedMethods: this.allowedMethods(),
333336
cachedMethods: this.cachedMethods(),
334337
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
@@ -352,7 +355,7 @@ export class StacksCloud extends Stack {
352355

353356
// if docMode is used, we don't need to add a behavior for the docs
354357
// because the docs will be the root of the site
355-
if (this.shouldDeployDocs() && !app.docMode) {
358+
if (this.shouldDeployDocs() && !config.app.docMode) {
356359
behaviorOptions = {
357360
...this.docsBehaviorOptions(),
358361
...behaviorOptions,
@@ -394,8 +397,8 @@ export class StacksCloud extends Stack {
394397
originPath: '/docs',
395398
}),
396399
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),
399402
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
400403
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
401404
},
@@ -405,8 +408,8 @@ export class StacksCloud extends Stack {
405408
originPath: '/docs',
406409
}),
407410
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),
410413
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
411414
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
412415
},
@@ -425,7 +428,7 @@ export class StacksCloud extends Stack {
425428
})
426429

427430
new Output(this, 'ApiUrl', {
428-
value: `https://${this.domain}/${this.apiPath}`,
431+
value: `https://${this.domain}/${this.apiPrefix}`,
429432
description: 'The URL of the deployed application',
430433
})
431434

@@ -438,7 +441,7 @@ export class StacksCloud extends Stack {
438441

439442
if (this.shouldDeployDocs()) {
440443
new Output(this, 'DocsUrl', {
441-
value: `https://${this.domain}/${this.apiPath}`,
444+
value: `https://${this.domain}/${this.apiPrefix}`,
442445
description: 'The URL of the deployed documentation',
443446
})
444447
}

.stacks/core/config/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const config: StacksOptions = {
88
}
99

1010
export const {
11+
api,
1112
app,
1213
binary,
1314
cache,

0 commit comments

Comments
 (0)