-
Notifications
You must be signed in to change notification settings - Fork 191
/
sst.config.ts
119 lines (116 loc) · 3.34 KB
/
sst.config.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/// <reference path="./.sst/platform/config.d.ts" />
export default $config({
app(input) {
return {
name: "www",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
console: {
autodeploy: {
target(event) {
if (
event.type === "branch" &&
event.branch === "dev" &&
event.action === "pushed"
) {
return { stage: "production" };
}
},
workflow(ctx) {
ctx.install();
ctx.shell("goenv install 1.21.3 && goenv global 1.21.3");
ctx.shell("cd ../platform && ./scripts/build");
ctx.shell("npm -g i sst");
ctx.deploy();
},
},
},
async run() {
const domain =
{
production: "sst.dev",
dev: "dev.sst.dev",
}[$app.stage] || $app.stage + "dev.sst.dev";
// Redirect /examples to guide.sst.dev/examples
// Redirect /chapters to guide.sst.dev/chapters
// Redirect /archives to guide.sst.dev/archives
const cfFunction = new aws.cloudfront.Function("AstroRedirect", {
runtime: "cloudfront-js-2.0",
code: [
`function handler(event) {`,
` const request = event.request;`,
// ie. request.uri is /examples/foo
` return {`,
` statusCode: 302,`,
` statusDescription: 'Found',`,
` headers: {`,
` location: { value: "https://guide.sst.dev" + request.uri }`,
` },`,
` };`,
`}`,
].join("\n"),
});
const behaviorConfig = {
targetOriginId: "redirect",
viewerProtocolPolicy: "redirect-to-https",
allowedMethods: ["GET", "HEAD", "OPTIONS"],
cachedMethods: ["GET", "HEAD"],
functionAssociations: [
{ eventType: "viewer-request", functionArn: cfFunction.arn },
],
forwardedValues: {
queryString: true,
headers: ["Origin"],
cookies: { forward: "none" },
},
};
new sst.aws.Astro("Astro", {
domain:
$app.stage === "production"
? {
name: domain,
redirects: [
"www.sst.dev",
"ion.sst.dev",
"serverless-stack.com",
"www.serverless-stack.com",
],
}
: domain,
transform: {
cdn: (args) => {
args.origins = $output(args.origins).apply((origins) => [
...origins,
{
domainName: "guide.sst.dev",
originId: "redirect",
customOriginConfig: {
httpPort: 80,
httpsPort: 443,
originProtocolPolicy: "https-only",
originReadTimeout: 20,
originSslProtocols: ["TLSv1.2"],
},
},
]);
args.orderedCacheBehaviors = $output(
args.orderedCacheBehaviors
).apply((cacheBehaviors) => [
...(cacheBehaviors || []),
{ pathPattern: "/examples*", ...behaviorConfig },
{ pathPattern: "/chapters*", ...behaviorConfig },
{ pathPattern: "/archives*", ...behaviorConfig },
]);
},
},
});
new sst.aws.Router("TelemetryRouter", {
domain: "telemetry.ion." + domain,
routes: {
"/*": "https://us.i.posthog.com",
},
});
},
});