@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
mdx 162 lines 4.56 KB
Raw
1 ---
2 title: Astro
3 description: Deploy Astro SSR or a fully static site to Prisma Compute with Prisma.Website.Astro, running on Bun with native Astro dev locally.
4 sidebar:
5 order: 11
6 ---
7
8 import PackageManagers from "../../../../components/PackageManagers.astro";
9
10 export const devDeps = "@alchemy.run/frontend-frameworks @vercel/nft";
11
12 `Prisma.Website.Astro` builds an [Astro](https://astro.build) project
13 with the shared Node target and runs it on **Bun in Prisma Compute**.
14 Assets are served first, then the Astro SSR handler. Fully static
15 output uses a static-file server on the same Compute runtime. Both
16 paths upload a `tar.gz` artifact, not a container image.
17
18 ## Install
19
20 Install the build-time integration in your Astro project. The resource
21 loads its `/astro` and `/astro/node` exports:
22
23 <PackageManagers dev={devDeps} />
24
25 ## Configure Astro
26
27 Your `astro.config.*` loads natively, including integrations and Vite
28 plugins. Do not declare an `adapter`: Alchemy injects the Node-target
29 adapter and rejects a conflicting adapter. The deployed runtime is Bun,
30 not a Node container.
31
32 ## Declare the Website
33
34 ```typescript
35 // alchemy.run.ts
36 import * as Prisma from "@alchemy.run/prisma";
37
38 export const Website = Prisma.Website.Astro("Website");
39 ```
40
41 Pass `rootDir` when `package.json` is not at `.`. Omit `project` to
42 create a database-less Prisma project on live deploy, or pass an
43 existing project.
44
45 ## Add it to the Stack
46
47 ```typescript
48 // alchemy.run.ts
49 import * as Alchemy from "alchemy";
50 import * as Effect from "effect/Effect";
51
52 export default Alchemy.Stack(
53 "MyAstroSite",
54 { providers: Prisma.providers(), state: Alchemy.localState() },
55 Effect.gen(function* () {
56 const site = yield* Website;
57 return { url: site.url };
58 }),
59 );
60 ```
61
62 Pages render on demand by default. A page with
63 `export const prerender = true` is generated at build time and served
64 as a file. `site.url` is the Compute endpoint on deploy.
65
66 ## Add environment variables
67
68 ```diff lang="typescript"
69 export const Website = Prisma.Website.Astro("Website", {
70 + env: {
71 + GREETING: "Hello from Alchemy!",
72 + API_BASE: "https://api.example.com",
73 + },
74 });
75 ```
76
77 `env` accepts strings or `Redacted` values. It is applied before build
78 and dev and passed to Compute as process environment, not Worker bindings.
79
80 ## Read the environment in server code
81
82 ```astro
83 ---
84 // src/pages/index.astro
85 const greeting = process.env.GREETING ?? "hello";
86 ---
87
88 <h1>{greeting}</h1>
89 ```
90
91 Server-rendered pages read the Bun process environment. Astro inlines
92 `PUBLIC_*` values at build time, so keep secrets out of those keys.
93
94 ## Fully static sites
95
96 ```typescript
97 export const Website = Prisma.Website.Astro("Website", {
98 astro: { output: "static" },
99 assets: { notFoundHandling: "404-page" },
100 });
101 ```
102
103 Every page is prerendered. There is no Astro request handler, but
104 **Compute still runs the static-file server**. This is not a CDN-only
105 deployment. `assets.notFoundHandling` applies to static output:
106 `"404-page"` serves `404.html` for misses; `"single-page-application"`
107 returns the index page with status 200.
108
109 ## Astro configuration
110
111 Keep integrations and plugins in your native config:
112
113 ```typescript
114 // astro.config.ts
115 import { defineConfig } from "astro/config";
116 import react from "@astrojs/react";
117 import tailwindcss from "@tailwindcss/vite";
118
119 export default defineConfig({
120 site: "https://blog.example.com",
121 integrations: [react()],
122 vite: { plugins: [tailwindcss()] },
123 });
124 ```
125
126 The `astro` bag holds deploy-specific overrides:
127
128 ```typescript
129 export const Website = Prisma.Website.Astro("Website", {
130 astro: { site: "https://preview.example.com" },
131 });
132 ```
133
134 Alchemy owns `adapter` and defaults `output` to `"server"`, even when
135 the file sets another output. Select static output on the resource.
136 The bag also exposes `base`, `srcDir`, `publicDir`, `outDir`, and
137 `trailingSlash`.
138
139 ## Local dev
140
141 `bun alchemy dev` starts Astro's own server with HMR; the Website
142 creates no Prisma resources. `site.url` is the local address.
143 `.pipe(Alchemy.remote())` opts into the live deployment during dev.
144
145 ## Custom domain
146
147 ```typescript
148 export const Website = Prisma.Website.Astro("Website", {
149 domain: "app.example.com",
150 });
151 ```
152
153 Configure the returned `dnsRecords` yourself and verify
154 status before routing traffic. See
155 [Custom domains](/prisma/frontend/websites#custom-domains).
156
157 ## Where next
158
159 - [Astro API](/providers/prisma/website/astro).
160 - [Astro example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-website-astro).
161 - [Static sites](/prisma/frontend/static-site) and [Websites](/prisma/frontend/websites).
162 - [Compute apps](/prisma/compute/apps) and [Setup](/prisma/setup).