-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsst.config.ts
More file actions
90 lines (85 loc) · 2.56 KB
/
sst.config.ts
File metadata and controls
90 lines (85 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/// <reference path="./.sst/platform/config.d.ts" />
export default $config({
app(input) {
return {
name: 're-fit',
removal: input?.stage === 'prod' ? 'retain' : 'remove',
home: 'aws',
providers: {
aws: {
region: 'ap-northeast-2',
},
},
};
},
async run() {
const envKeys = [
'NEXT_PUBLIC_API_BASE_URL',
'NEXT_PUBLIC_KAKAO_REDIRECT_URL',
'NEXT_PUBLIC_WS_URL',
'NEXT_PUBLIC_API_PATH_SUFFIX',
'NEXT_PUBLIC_API_PATH_SUFFIX_TARGETS',
'NEXT_PUBLIC_APP_URL',
'NEXT_PUBLIC_METRICS_ENABLED',
] as const;
const environment: Record<string, string> = {};
for (const key of envKeys) {
if (process.env[key]) {
environment[key] = process.env[key];
}
}
const BACKEND_ORIGIN_ID = 'backendAlb';
const rawApiUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
if (!rawApiUrl) throw new Error('NEXT_PUBLIC_API_BASE_URL is required');
const BACKEND_DOMAIN = rawApiUrl.replace(/^https?:\/\//, '').trim();
const BACKEND_PATH_PATTERNS = ['/swagger-ui/*', '/v3/api-docs*', '/actuator/*'];
new sst.aws.Nextjs('ReFitWeb', {
domain: {
name: 're-fit.kr',
cert: process.env.ACM_CERTIFICATE_ARN,
dns: false,
},
warm: 3,
server: {
memory: '1769 MB',
timeout: '30 seconds',
},
environment,
transform: {
cdn: (args) => {
args.origins = $resolve(args.origins).apply((origins) => [
...origins,
{
domainName: BACKEND_DOMAIN,
originId: BACKEND_ORIGIN_ID,
customOriginConfig: {
httpPort: 80,
httpsPort: 443,
originProtocolPolicy: 'https-only',
originSslProtocols: ['TLSv1.2'],
},
},
]);
args.orderedCacheBehaviors = $resolve(
args.orderedCacheBehaviors ?? [],
).apply((behaviors) => [
...behaviors,
...BACKEND_PATH_PATTERNS.map((pathPattern) => ({
pathPattern,
targetOriginId: BACKEND_ORIGIN_ID,
viewerProtocolPolicy: 'redirect-to-https' as const,
allowedMethods: ['GET', 'HEAD', 'OPTIONS'],
cachedMethods: ['GET', 'HEAD'],
compress: true,
forwardedValues: {
queryString: true,
headers: ['Authorization'],
cookies: { forward: 'none' },
},
})),
]);
},
},
});
},
});