The best way to control Claude Code, Codex and more from any computer or phone

main
ts 41 lines 1.49 KB
Raw
1 import { fileURLToPath } from "node:url";
2 import * as GCP from "@alchemy.run/gcp";
3 import * as Alchemy from "alchemy";
4 import * as Output from "alchemy/Output";
5 import * as Effect from "effect/Effect";
6
7 export default Alchemy.Stack(
8 "GcpStaticSiteExample",
9 { providers: GCP.providers(), state: Alchemy.localState() },
10 Effect.gen(function* () {
11 const bucket = yield* GCP.Storage.Bucket("Site", {
12 uniformBucketLevelAccess: true,
13 // Applied when the bucket is served through a CNAME or an HTTPS
14 // load balancer; path-style storage.googleapis.com URLs ignore it.
15 website: { mainPageSuffix: "index.html", notFoundPage: "404.html" },
16 // Site content is fully owned by this stack.
17 forceDestroy: true,
18 });
19
20 // Anyone on the internet may read (and list) the site's objects.
21 yield* GCP.IAM.Member("PublicRead", {
22 kind: "storage.bucket",
23 name: bucket.bucketName,
24 role: "roles/storage.objectViewer",
25 member: "allUsers",
26 });
27
28 const files = yield* GCP.Storage.Files("SiteFiles", {
29 bucketName: bucket.bucketName,
30 path: fileURLToPath(new URL("./site", import.meta.url)),
31 // HTML revalidates on every load so deploys show up immediately.
32 cacheControl: (key) => (key.endsWith(".html") ? "no-cache" : "public, max-age=300"),
33 });
34
35 return {
36 bucketName: bucket.bucketName,
37 url: Output.interpolate`https://storage.googleapis.com/${bucket.bucketName}/index.html`,
38 fileCount: files.length,
39 };
40 }),
41 );