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