Skip to content

Commit 458e34b

Browse files
committed
chore: wip
chore: wip
1 parent 8c35844 commit 458e34b

File tree

3 files changed

+104
-16
lines changed

3 files changed

+104
-16
lines changed

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

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,39 @@ export class StacksCloud extends Stack {
2525
if (!app.url)
2626
throw new Error('./config app.url is not defined')
2727

28+
const domainName = app.url
29+
2830
const zone = new route53.PublicHostedZone(this, 'HostedZone', {
29-
zoneName: 'stacksjs.com',
31+
zoneName: domainName,
3032
})
3133

3234
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),
3542
})
3643

3744
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}`,
3953
versioned: true,
4054
removalPolicy: RemovalPolicy.DESTROY,
4155
autoDeleteObjects: true,
4256
})
4357

4458
// Create an S3 bucket for CloudFront access logs
4559
const logBucket = new s3.Bucket(this, 'LogBucket', {
46-
bucketName: 'stacksjs.com34534545-logs',
60+
bucketName: `${domainName}-logs-${app.env}`,
4761
removalPolicy: RemovalPolicy.DESTROY,
4862
autoDeleteObjects: true,
4963
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_PREFERRED,
@@ -69,11 +83,11 @@ export class StacksCloud extends Stack {
6983

7084
const originAccessIdentity = new cloudfront.OriginAccessIdentity(this, 'OAI')
7185

72-
// // create a CDN to deploy your website
86+
// create a CDN to deploy your website
7387
const distribution = new cloudfront.Distribution(this, 'Distribution', {
74-
domainNames: ['stacksjs.com'],
88+
domainNames: [domainName],
7589
defaultRootObject: 'index.html',
76-
comment: `CDN for ${app.name}`,
90+
comment: `CDN for ${app.url}`,
7791
certificate,
7892
// originShieldEnabled: true,
7993
enableLogging: true,
@@ -112,24 +126,71 @@ export class StacksCloud extends Stack {
112126
// ],
113127
})
114128

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+
115171
// Create a Route53 record pointing to the CloudFront distribution
116172
// eslint-disable-next-line no-new
117173
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}`,
119183
zone,
120-
// recordName: domainName,
121184
target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(distribution)),
122185
})
123186

124187
// eslint-disable-next-line no-new
125188
new route53.CnameRecord(this, 'WwwCnameRecord', {
126189
zone,
127190
recordName: 'www',
128-
domainName: 'stacksjs.com',
191+
domainName,
129192
})
130193

131-
// housekeeping for uploading the data in the bucket
132-
133194
// eslint-disable-next-line no-new
134195
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
135196
sources: [s3deploy.Source.asset('../../../storage/public')],
@@ -138,13 +199,28 @@ export class StacksCloud extends Stack {
138199
distributionPaths: ['/*'],
139200
})
140201

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+
141210
// Prints out the web endpoint to the terminal
142211
// eslint-disable-next-line no-new
143212
new Output(this, 'AppUrl', {
144-
value: 'https://stacksjs.com',
213+
value: `https://${domainName}`,
145214
description: 'The URL of the deployed application',
146215
})
147216

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+
148224
// Prints out the web endpoint to the terminal
149225
// eslint-disable-next-line no-new
150226
new Output(this, 'VanityUrl', {

.stacks/core/types/src/app.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ export interface AppOptions {
3535
* the Buddy command line tool. You should set this to the root of
3636
* your application so that it is used when running Buddy tasks.
3737
*
38-
* @default string "https://stacks.test"
39-
* @example "https://my-project.test"
38+
* @default string "stacks.test"
39+
* @example "my-project.test"
4040
*/
4141
url: string
4242

43+
/**
44+
* **Subdomains**
45+
*/
46+
subdomains: {
47+
docs: string
48+
api: string
49+
}
50+
4351
/**
4452
* **Application Debug Mode**
4553
*

config/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default {
1212
name: env.APP_NAME || 'Stacks',
1313
env: env.APP_ENV || 'development',
1414
url: env.APP_URL || 'stacks.test',
15+
subdomains: {
16+
docs: env.APP_SUBDOMAIN_DOCS || 'docs',
17+
api: env.APP_SUBDOMAIN_API || 'api',
18+
},
1519
debug: env.APP_DEBUG || false,
1620
key: env.APP_KEY,
1721

0 commit comments

Comments
 (0)