@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 182 lines 5.22 KB
Raw
1 ---
2 title: Nuxt
3 description: Deploy a Nuxt app to Fly with Fly.Website.Nuxt — nitro's node preset on a Machine, assets baked into the image, and Nuxt's own dev server under alchemy dev.
4 sidebar:
5 order: 10
6 ---
7
8 import PackageManagers from "../../../../components/PackageManagers.astro";
9
10 export const devDeps = "@alchemy.run/frontend-frameworks";
11
12 `Fly.Website.Nuxt` deploys a [Nuxt](https://nuxt.com) app to Fly. It
13 builds the app through your project's own `@nuxt/kit` with nitro's
14 `node` preset: the nitro Node server runs on a Machine, and client
15 assets plus prerendered pages are baked into the image. Omit `app`
16 and a `Fly.App` is created under the site; a `Fly.Service` listens
17 on port 3000 and a shared IPv4 assignment makes
18 `https://{app}.fly.dev` answer. There is no `nitro.preset` to edit
19 and no build command to run.
20
21 ## Install
22
23 The build integration is not bundled with alchemy. Install
24 `@alchemy.run/frontend-frameworks`; the resource loads its `/nuxt`
25 and `/nuxt/node` exports from your project at deploy time. It is
26 only used at build time, so a dev dependency is enough:
27
28 <PackageManagers dev={devDeps} />
29
30 ## Configure Nuxt
31
32 Your `nuxt.config.ts` loads natively — modules, layers, and all —
33 so configure Nuxt exactly as you would outside Alchemy:
34
35 ```typescript
36 // nuxt.config.ts
37 export default defineNuxtConfig({
38 modules: ["@nuxtjs/tailwindcss"],
39 routeRules: {
40 "/about": { prerender: true },
41 },
42 });
43 ```
44
45 Deploy-specific overrides are merged over it via the `nuxt` prop
46 (the override wins) — see [Prerendering](#prerendering) below for an
47 example.
48
49 Don't set `nitro.preset` — the Node deploy target owns the preset
50 (`"node"`), and a foreign preset is a hard error.
51
52 ## Declare the Website
53
54 Declare the site as a module-level const (rather than inline in the
55 Stack):
56
57 ```typescript
58 // alchemy.run.ts
59 import * as Fly from "@alchemy.run/fly";
60
61 export const Website = Fly.Website.Nuxt("Website");
62 ```
63
64 Pass `rootDir` if `package.json` is not at `.`. Pass `app` to put
65 the Service on an App you already declared; otherwise the site
66 creates `Fly.App("App")` under its namespace.
67
68 ## Add it to the Stack
69
70 Yield the site from your Stack and return its URL:
71
72 ```typescript
73 // alchemy.run.ts
74 import * as Alchemy from "alchemy";
75 import * as Effect from "effect/Effect";
76
77 export default Alchemy.Stack(
78 "MyNuxtSite",
79 {
80 providers: Fly.providers(),
81 state: Alchemy.localState(),
82 },
83 Effect.gen(function* () {
84 const site = yield* Website;
85 return { url: site.url };
86 }),
87 );
88 ```
89
90 On deploy the site is one App, one Service on port 3000, and a
91 `shared_v4` IpAssignment. `site.url` is `https://{app}.fly.dev`
92 (or `https://{domain}` when you set `domain`). `site.app`,
93 `site.service`, `site.ip`, and `site.certificate` are undefined
94 under `alchemy dev`.
95
96 ## Add environment variables
97
98 Process environment is the top-level `env` prop — plain strings, or
99 `Redacted` values. They are copied onto `process.env` before build
100 and `alchemy dev`, and onto the Machine at deploy:
101
102 ```diff lang="typescript"
103 // alchemy.run.ts
104 export const Website = Fly.Website.Nuxt("Website", {
105 + env: {
106 + GREETING: "Hello from Alchemy!",
107 + NUXT_PUBLIC_API_BASE: "https://api.example.com",
108 + },
109 });
110 ```
111
112 This is the hosted Node process, not Worker bindings.
113 `NUXT_`-prefixed keys override Nuxt `runtimeConfig` the usual way;
114 `NUXT_PUBLIC_` values are inlined into the client at build time.
115
116 ## Read the environment in server code
117
118 The nitro server is a plain Node process, so server routes and SSR
119 read the environment from `process.env`:
120
121 ```typescript
122 // server/api/hello.ts
123 export default defineEventHandler(() => {
124 return { greeting: process.env.GREETING ?? "hello" };
125 });
126 ```
127
128 ## Prerendering
129
130 Routes marked for prerendering in `routeRules` (or via
131 `nitro.prerender`) render at build time into `.output/public` and
132 are baked into the image, served as static files before the nitro
133 handler:
134
135 ```typescript
136 export const Website = Fly.Website.Nuxt("Website", {
137 nuxt: {
138 routeRules: {
139 "/about": { prerender: true },
140 },
141 },
142 });
143 ```
144
145 Nitro's `isr` route rule is implemented only by the Vercel and
146 Netlify presets. On the Node preset it is silently ignored at build
147 time, and the route renders on demand like any other SSR route. Use
148 `prerender` for build-time static routes, or `cache` route rules for
149 runtime caching.
150
151 ## Local dev
152
153 ```sh
154 bun alchemy dev
155 ```
156
157 `alchemy dev` runs Nuxt's own dev server (nitro dev, full HMR)
158 instead of deploying; `site.url` is the local address and no Fly
159 resources are created. Wrap the site in `Alchemy.remote()` to deploy
160 the live App and Service even during dev.
161
162 ## Custom domain
163
164 `domain` is a hostname string. The site requests an ACME
165 [`Fly.Certificate`](/fly/networking#use-your-own-hostname) on the
166 App and `url` becomes `https://{domain}`. Point DNS at the App
167 yourself — v1 does not create DNS records:
168
169 ```typescript
170 export const Website = Fly.Website.Nuxt("Website", {
171 domain: "app.example.com",
172 });
173 ```
174
175 ## Where next
176
177 - [`Fly.Website.Nuxt` reference](/providers/fly/website/nuxt) —
178 every prop and attribute.
179 - [Services](/fly/compute/services) and [Apps](/fly/compute/apps) —
180 the Service and App the site creates.
181 - [IPs & certificates](/fly/networking) — shared IPv4 and ACME.
182 - [Setup](/fly/setup) — org, API token, and alchemy login.