| 1 | --- |
| 2 | title: Waku |
| 3 | description: Deploy a Waku app to Railway with Railway.Website.Waku — RSC server on a container Service, SSG pages in the image, and Waku's own dev server under alchemy dev. |
| 4 | sidebar: |
| 5 | order: 13 |
| 6 | --- |
| 7 | |
| 8 | import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks"; |
| 11 | |
| 12 | `Railway.Website.Waku` deploys a [Waku](https://waku.gg) app (React |
| 13 | Server Components) to Railway. It builds the project programmatically: |
| 14 | the RSC server plus SSG pages run on one |
| 15 | [`Railway.Service`](/railway/compute/services). Alchemy creates a |
| 16 | [`Railway.Project`](/railway/compute/projects) if you omit |
| 17 | `project`. The URL is the generated `*.up.railway.app` hostname. No |
| 18 | `waku.config.ts` edits are required — if you have one it loads |
| 19 | natively — and there is no adapter to configure and no build command |
| 20 | to run. |
| 21 | |
| 22 | ## Install |
| 23 | |
| 24 | The build integration is not bundled with alchemy. Install |
| 25 | `@alchemy.run/frontend-frameworks`; the resource loads its `/waku` |
| 26 | and `/waku/node` exports from your project at deploy time. It is only |
| 27 | used at build time, so a dev dependency is enough: |
| 28 | |
| 29 | <Tabs syncKey="pkgManager"> |
| 30 | <TabItem label="bun" icon="bun"> |
| 31 | <Code code={`bun add -d ${devDeps}`} lang="sh" /> |
| 32 | </TabItem> |
| 33 | <TabItem label="npm" icon="npm"> |
| 34 | <Code code={`npm install -D ${devDeps}`} lang="sh" /> |
| 35 | </TabItem> |
| 36 | <TabItem label="pnpm" icon="pnpm"> |
| 37 | <Code code={`pnpm add -D ${devDeps}`} lang="sh" /> |
| 38 | </TabItem> |
| 39 | <TabItem label="yarn" icon="seti:yarn"> |
| 40 | <Code code={`yarn add -D ${devDeps}`} lang="sh" /> |
| 41 | </TabItem> |
| 42 | </Tabs> |
| 43 | |
| 44 | ## Configure Waku |
| 45 | |
| 46 | No framework config is required — a fresh Waku project deploys |
| 47 | as-is. If your project has a `waku.config.ts`, Alchemy loads it |
| 48 | natively (exactly as Waku's own CLI does) and uses it as the base |
| 49 | config — including Vite plugins under its `vite` field: |
| 50 | |
| 51 | ```typescript |
| 52 | // waku.config.ts |
| 53 | import tailwindcss from "@tailwindcss/vite"; |
| 54 | import { defineConfig } from "waku/config"; |
| 55 | |
| 56 | export default defineConfig({ |
| 57 | basePath: "/", |
| 58 | vite: { |
| 59 | plugins: [tailwindcss()], |
| 60 | }, |
| 61 | }); |
| 62 | ``` |
| 63 | |
| 64 | Options set on the resource (`srcDir`, `distDir`, `basePath`) merge |
| 65 | over the file, per key. The one key Alchemy owns is |
| 66 | `unstable_adapter` — the Node deploy target sets it. Setting it |
| 67 | fails the build with an actionable error. |
| 68 | |
| 69 | :::note |
| 70 | Vite configuration must live in `waku.config.ts`'s `vite` field — |
| 71 | a standalone `vite.config.ts` is not loaded, same as Waku's own CLI. |
| 72 | ::: |
| 73 | |
| 74 | ## Declare the Website |
| 75 | |
| 76 | Declare the site as a module-level const (rather than inline in the |
| 77 | Stack): |
| 78 | |
| 79 | ```typescript |
| 80 | // alchemy.run.ts |
| 81 | import * as Railway from "alchemy/Railway"; |
| 82 | |
| 83 | export const Website = Railway.Website.Waku("Website"); |
| 84 | ``` |
| 85 | |
| 86 | Pass `project` to put the Service in an existing `Railway.Project`. |
| 87 | `rootDir` defaults to `"."`. |
| 88 | |
| 89 | ## Add it to the Stack |
| 90 | |
| 91 | Yield the site from your Stack and return its URL: |
| 92 | |
| 93 | ```typescript |
| 94 | // alchemy.run.ts |
| 95 | import * as Alchemy from "alchemy"; |
| 96 | import * as Effect from "effect/Effect"; |
| 97 | |
| 98 | export default Alchemy.Stack( |
| 99 | "MyWakuSite", |
| 100 | { |
| 101 | providers: Railway.providers(), |
| 102 | state: Alchemy.localState(), |
| 103 | }, |
| 104 | Effect.gen(function* () { |
| 105 | const site = yield* Website; |
| 106 | return { url: site.url }; |
| 107 | }), |
| 108 | ); |
| 109 | ``` |
| 110 | |
| 111 | Pages rendered as `"static"` are generated at build time and baked |
| 112 | into the image; dynamic pages and API routes run on the Service. |
| 113 | SSG pages are served at their extensionless URLs (`/about`). |
| 114 | |
| 115 | The live `url` is `https://{name}.up.railway.app`. `site.service` |
| 116 | and `site.project` are the Railway resources underneath — |
| 117 | `undefined` during `alchemy dev`. |
| 118 | |
| 119 | See the [Waku API reference](/providers/railway/website/waku) for |
| 120 | every prop and attribute. |
| 121 | |
| 122 | ## Add environment variables |
| 123 | |
| 124 | Process environment is a top-level `env` map — plain strings, or |
| 125 | `Redacted` values: |
| 126 | |
| 127 | ```diff lang="typescript" |
| 128 | // alchemy.run.ts |
| 129 | export const Website = Railway.Website.Waku("Website", { |
| 130 | + env: { |
| 131 | + GREETING: "Hello from alchemy", |
| 132 | + API_BASE: "https://api.example.com", |
| 133 | + }, |
| 134 | }); |
| 135 | ``` |
| 136 | |
| 137 | The values are copied onto `process.env` before the build and the |
| 138 | dev server, and onto the Service at deploy time, so server code |
| 139 | reads the same keys in both modes. Client inlining is whatever Vite |
| 140 | does (`VITE_` prefixes). |
| 141 | |
| 142 | ## Read the environment in server code |
| 143 | |
| 144 | The RSC server is a plain Node process. Server components and API |
| 145 | routes read `process.env` (Waku's `getEnv` reads the same values): |
| 146 | |
| 147 | ```typescript |
| 148 | // src/pages/index.tsx |
| 149 | export default async function HomePage() { |
| 150 | const greeting = process.env.GREETING ?? "hello"; |
| 151 | return <h1>{greeting}</h1>; |
| 152 | } |
| 153 | |
| 154 | export const getConfig = async () => ({ render: "dynamic" }) as const; |
| 155 | ``` |
| 156 | |
| 157 | ## Local dev |
| 158 | |
| 159 | ```sh |
| 160 | bun alchemy dev |
| 161 | ``` |
| 162 | |
| 163 | `alchemy dev` runs Waku's own dev server (native HMR) instead of |
| 164 | deploying; `site.url` is the local address and no Railway resources |
| 165 | are created. Wrap the site in |
| 166 | `Alchemy.remote()` to deploy the live Service even during dev: |
| 167 | |
| 168 | ```typescript |
| 169 | export const Website = Railway.Website.Waku("Website").pipe(Alchemy.remote()); |
| 170 | ``` |
| 171 | |
| 172 | ## Custom domain |
| 173 | |
| 174 | ```typescript |
| 175 | const site = yield* Railway.Website.Waku("Web", { |
| 176 | domain: "app.example.com", |
| 177 | }); |
| 178 | ``` |
| 179 | |
| 180 | `domain` attaches a [`Railway.CustomDomain`](/railway/networking) |
| 181 | (`targetPort` 3000). `url` becomes `https://app.example.com` |
| 182 | instead of the generated `*.up.railway.app`. |
| 183 | |
| 184 | ## Where next |
| 185 | |
| 186 | - [Waku API reference](/providers/railway/website/waku) |
| 187 | - [Projects](/railway/compute/projects) and |
| 188 | [Services](/railway/compute/services) |
| 189 | - [Custom domains](/railway/networking) |