Skip to content

Commit c48468e

Browse files
committed
chore: wip
1 parent 0b057b5 commit c48468e

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

config/cloud.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export default {
3232
},
3333

3434
ai: true, // deploys AI endpoints
35-
docs: true, // deploys project documentation
36-
api: true, // deploys project API
35+
docs: true, // deploys documentation
36+
api: true, // deploys API
3737
fileSystem: true, // enables file system
3838

3939
// compute: {},

storage/framework/stacks/src/cloud/src/cloud/ai.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ export class AiStack {
9797
// })
9898

9999
new Output(scope, 'AiVanityAskApiUrl', {
100-
value: `${api.url}/ask`,
100+
value: `${api.url}ask`,
101101
})
102102

103103
new Output(scope, 'AiVanitySummarizeApiUrl', {
104-
value: `${api.url}/summarize`,
104+
value: `${api.url}summarize`,
105105
})
106106

107107
new Output(scope, 'AiAskApiUrl', {

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { hasFiles } from '@stacksjs/storage'
1414
import { path as p } from '@stacksjs/path'
1515
import { env } from '@stacksjs/env'
1616
import type { NestedCloudProps } from '../types'
17-
import type { EnvKey } from '../../../../../stack/env'
17+
import type { EnvKey } from '../../../../../stacks/env'
1818

1919
export interface CdnStackProps extends NestedCloudProps {
2020
certificate: acm.Certificate
@@ -23,6 +23,8 @@ export interface CdnStackProps extends NestedCloudProps {
2323
firewall: wafv2.CfnWebACL
2424
originRequestFunction: lambda.Function
2525
zone: route53.IHostedZone
26+
webServer: lambda.Function
27+
webServerUrl: lambda.FunctionUrl
2628
}
2729

2830
export class CdnStack {
@@ -190,29 +192,25 @@ export class CdnStack {
190192
}
191193

192194
apiBehaviorOptions(scope: Construct, props: CdnStackProps): Record<string, cloudfront.BehaviorOptions> {
193-
const origin = new origins.HttpOrigin(props.lb.loadBalancerDnsName, {
195+
const origin = (path: '/api' | '/api/*' = '/api') => new origins.HttpOrigin(props.webServerUrl.url, {
194196
originPath: path,
195-
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTP_ONLY,
197+
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
196198
})
197-
// const origin = (path: '/api' | '/api/*' = '/api') => new origins.LoadBalancerV2Origin(props.lb, {
198-
// originPath: path,
199-
// protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
200-
// })
201199

202200
return {
203201
'/api': {
204-
origin,
202+
origin: origin(),
205203
compress: true,
206204
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
207-
// cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
205+
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
208206
cachePolicy: this.setApiCachePolicy(scope),
209207
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
210208
},
211209
'/api/*': {
212-
origin,
210+
origin: origin('/api/*'),
213211
compress: true,
214212
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
215-
// cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
213+
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
216214
cachePolicy: this.apiCachePolicy,
217215
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
218216
},
@@ -252,13 +250,13 @@ export class CdnStack {
252250
return {
253251
'/ai/ask': {
254252
origin: new origins.HttpOrigin('9qp44a2b7e.execute-api.us-east-1.amazonaws.com', {
255-
originPath: '/prod',
253+
originPath: '/ai',
256254
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
257255
}),
258256
compress: false,
259257
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
260258
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
261-
cachePolicy: new cloudfront.CachePolicy(scope, 'ApiCachePolicy', {
259+
cachePolicy: new cloudfront.CachePolicy(scope, 'AiCachePolicy', {
262260
comment: 'Stacks AI Cache Policy',
263261
cachePolicyName: `${this.props.slug}-${this.props.appEnv}-ai-cache-policy`,
264262
defaultTtl: Duration.seconds(0),
@@ -300,7 +298,7 @@ export class CdnStack {
300298
const keysToRemove = ['_HANDLER', '_X_AMZN_TRACE_ID', 'AWS_REGION', 'AWS_EXECUTION_ENV', 'AWS_LAMBDA_FUNCTION_NAME', 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE', 'AWS_LAMBDA_FUNCTION_VERSION', 'AWS_LAMBDA_INITIALIZATION_TYPE', 'AWS_LAMBDA_LOG_GROUP_NAME', 'AWS_LAMBDA_LOG_STREAM_NAME', 'AWS_ACCESS_KEY', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN', 'AWS_LAMBDA_RUNTIME_API', 'LAMBDA_TASK_ROOT', 'LAMBDA_RUNTIME_DIR', '_']
301299
keysToRemove.forEach(key => delete env[key as EnvKey])
302300

303-
// behaviorOptions = this.apiBehaviorOptions(scope, props)
301+
behaviorOptions = this.apiBehaviorOptions(scope, props)
304302
}
305303

306304
// if docMode is used, we don't need to add a behavior for the docs

storage/framework/stacks/src/cloud/src/cloud/compute.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Construct } from 'constructs'
55
import { path as p } from '@stacksjs/path'
66
import { env } from '@stacksjs/env'
77
import type { NestedCloudProps } from '../types'
8-
import type { EnvKey } from '../../../../../stack/env'
8+
import type { EnvKey } from '../../../../../stacks/env'
99

1010
export interface ComputeStackProps extends NestedCloudProps {
1111
vpc: ec2.Vpc
@@ -15,6 +15,9 @@ export interface ComputeStackProps extends NestedCloudProps {
1515
}
1616

1717
export class ComputeStack {
18+
apiServer: lambda.Function
19+
apiServerUrl: lambda.FunctionUrl
20+
1821
constructor(scope: Construct, props: ComputeStackProps) {
1922
const vpc = props.vpc
2023
const fileSystem = props.fileSystem
@@ -26,7 +29,7 @@ export class ComputeStack {
2629
// directory: p.cloudPath('src/server'),
2730
// })
2831

29-
const webServer = new lambda.Function(scope, 'WebServer', {
32+
this.apiServer = new lambda.Function(scope, 'WebServer', {
3033
description: 'The web server for the Stacks application',
3134
code: lambda.Code.fromAssetImage(p.cloudPath('src/server')),
3235
handler: lambda.Handler.FROM_IMAGE,
@@ -51,18 +54,18 @@ export class ComputeStack {
5154
},
5255
})
5356

54-
secrets.grantRead(webServer)
55-
webServer.addEnvironment('SECRETS_ARN', secrets.secretArn)
57+
secrets.grantRead(this.apiServer)
58+
this.apiServer.addEnvironment('SECRETS_ARN', secrets.secretArn)
5659

57-
const api = new lambda.FunctionUrl(scope, 'StacksServerUrl', {
58-
function: webServer,
60+
this.apiServerUrl = new lambda.FunctionUrl(scope, 'StacksServerUrl', {
61+
function: this.apiServer,
5962
authType: lambda.FunctionUrlAuthType.NONE, // becomes a public API
6063
cors: {
6164
allowedOrigins: ['*'],
6265
},
6366
})
6467

65-
const apiVanityUrl = api.url
68+
const apiVanityUrl = this.apiServerUrl.url
6669
const apiPrefix = 'api'
6770

6871
new Output(scope, 'ApiUrl', {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class Cloud extends Stack {
6161

6262
// new DashboardStack(this)
6363

64-
new ComputeStack(this, {
64+
const api = new ComputeStack(this, {
6565
...props,
6666
vpc: network.vpc,
6767
fileSystem: fileSystem.fileSystem,
@@ -79,6 +79,8 @@ export class Cloud extends Stack {
7979
firewall: security.firewall,
8080
originRequestFunction: docs.originRequestFunction,
8181
zone: dns.zone,
82+
webServer: api.apiServer,
83+
webServerUrl: api.apiServerUrl,
8284
})
8385

8486
new DeploymentStack(this, {

0 commit comments

Comments
 (0)