Skip to content

Commit 8e892d8

Browse files
committed
chore: wip
chore: wip
1 parent 482b426 commit 8e892d8

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

config/cloud.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default {
3232
},
3333

3434
ai: true, // deploys AI endpoints
35+
cli: true, // deploys CLI setup endpoint
3536
docs: true, // deploys documentation
3637
api: true, // deploys API
3738
fileSystem: true, // enables file system

storage/framework/core/cloud/src/cloud/cdn.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface CdnStackProps extends NestedCloudProps {
1818
zone: route53.IHostedZone
1919
webServer: lambda.Function
2020
webServerUrl: lambda.FunctionUrl
21+
cliSetupUrl: lambda.FunctionUrl
2122
}
2223

2324
export class CdnStack {
@@ -279,10 +280,41 @@ export class CdnStack {
279280
}
280281
}
281282

283+
cliSetupBehaviorOptions(scope: Construct, props: CdnStackProps): Record<string, cloudfront.BehaviorOptions> {
284+
// const url = new URL()
285+
const hostname = Fn.select(2, Fn.split('/', props.cliSetupUrl.url))
286+
287+
return {
288+
'/install': {
289+
origin: new origins.HttpOrigin(hostname, {
290+
// origin: new origins.HttpOrigin('tipevv3dfx35fb7ptyq7nrxtga0qkcgc.lambda-url.us-east-1.on.aws', {
291+
originPath: '/cli-setup',
292+
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
293+
}),
294+
compress: false,
295+
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
296+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
297+
cachePolicy: new cloudfront.CachePolicy(scope, 'CliSetupCachePolicy', {
298+
comment: 'Stacks CLI Setup Cache Policy',
299+
cachePolicyName: `${this.props.slug}-${this.props.appEnv}-cli-setup-cache-policy`,
300+
defaultTtl: Duration.seconds(0),
301+
// minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
302+
cookieBehavior: cloudfront.CacheCookieBehavior.none(),
303+
headerBehavior: cloudfront.CacheHeaderBehavior.none(),
304+
queryStringBehavior: cloudfront.CacheQueryStringBehavior.none(),
305+
}),
306+
},
307+
}
308+
}
309+
282310
shouldDeployAiEndpoints() {
283311
return config.cloud.ai
284312
}
285313

314+
shouldDeployCliSetup() {
315+
return config.cloud.cli
316+
}
317+
286318
shouldDeployDocs() {
287319
return hasFiles(p.projectPath('docs'))
288320
}
@@ -313,6 +345,13 @@ export class CdnStack {
313345
}
314346
}
315347

348+
if (this.shouldDeployCliSetup()) {
349+
behaviorOptions = {
350+
...this.cliSetupBehaviorOptions(scope, props),
351+
...behaviorOptions,
352+
}
353+
}
354+
316355
return behaviorOptions
317356
}
318357

storage/framework/core/cloud/src/cloud/cli.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export interface CliStackProps extends NestedCloudProps {
77
}
88

99
export class CliStack {
10+
cliSetupUrl: lambda.FunctionUrl
11+
1012
constructor(scope: Construct, props: CliStackProps) {
1113
const cliSetupFunc = new lambda.Function(scope, 'CliSetupFunction', {
1214
functionName: `${props.slug}-${props.appEnv}-cli-setup`,
@@ -19,7 +21,7 @@ export class CliStack {
1921

2022
// create a Lambda.FunctionUrl to be used in the CloudFront OriginRequestPolicy
2123
// this will be used to trigger the function
22-
const cliSetupUrl = new lambda.FunctionUrl(scope, 'CliSetupFunctionUrl', {
24+
this.cliSetupUrl = new lambda.FunctionUrl(scope, 'CliSetupFunctionUrl', {
2325
function: cliSetupFunc,
2426
authType: lambda.FunctionUrlAuthType.NONE,
2527
cors: {
@@ -28,7 +30,7 @@ export class CliStack {
2830
})
2931

3032
new Output(scope, 'CliSetupVanityUrl', {
31-
value: `${cliSetupUrl.url}cli-setup`,
33+
value: `${this.cliSetupUrl.url}cli-setup`,
3234
})
3335

3436
// once deployed, need to create logic in the cdn origin request to check if the request is for the cli

storage/framework/core/cloud/src/cloud/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export class Cloud extends Stack {
7272

7373
new AiStack(this, props)
7474

75+
const cli = new CliStack(this, props)
76+
7577
const cdn = new CdnStack(this, {
7678
...props,
7779
publicBucket: storage.publicBucket,
@@ -82,6 +84,7 @@ export class Cloud extends Stack {
8284
zone: dns.zone,
8385
webServer: api.apiServer,
8486
webServerUrl: api.apiServerUrl,
87+
cliSetupUrl: cli.cliSetupUrl,
8588
})
8689

8790
new DeploymentStack(this, {
@@ -90,7 +93,5 @@ export class Cloud extends Stack {
9093
privateBucket: storage.privateBucket,
9194
cdn: cdn.distribution,
9295
})
93-
94-
new CliStack(this, props)
9596
}
9697
}

storage/framework/core/types/src/cloud.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface CloudOptions {
7474
}
7575

7676
ai: boolean
77+
cli: boolean
7778
docs: boolean
7879
api: boolean
7980
fileSystem: boolean

0 commit comments

Comments
 (0)