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
| 1 | --- |
| 2 | title: Vinext |
| 3 | description: Deploy vinext to Railway with the shared Website API, native local development, and a platform-specific data cache. |
| 4 | sidebar: |
| 5 | order: 9.6 |
| 6 | --- |
| 7 | |
| 8 | import PackageManagers from "../../../../components/PackageManagers.astro"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks"; |
| 11 | |
| 12 | `Railway.Website.Vinext` builds with the Vinext Vite API for production and runs native |
| 13 | `vinext dev` locally. The built app runs in a Railway Service using vinext's production Node server. |
| 14 | Alchemy creates a Project when `project` is omitted. The container includes |
| 15 | `dist/` and runtime dependencies; `site.url` is the Railway service domain. |
| 16 | |
| 17 | ## Install |
| 18 | |
| 19 | Keep `vinext`, `react`, `react-dom`, and `react-server-dom-webpack` in your |
| 20 | application dependencies, with `vite` and `@vitejs/plugin-rsc` for building. |
| 21 | Add the Alchemy integration: |
| 22 | |
| 23 | <PackageManagers dev={devDeps} /> |
| 24 | |
| 25 | ## Configure vinext |
| 26 | |
| 27 | ```typescript |
| 28 | // vite.config.ts |
| 29 | import { defineConfig } from "vite"; |
| 30 | import vinext from "vinext"; |
| 31 | |
| 32 | export default defineConfig({ |
| 33 | plugins: [vinext({ prerender: true })], |
| 34 | }); |
| 35 | ``` |
| 36 | |
| 37 | Alchemy injects the target-specific data-cache adapter during deployment. |
| 38 | No Alchemy plugin is required in `vite.config.ts`; deployment settings belong on |
| 39 | `Website.Vinext`. Leave Cloudflare plugins and Worker entrypoints out of this application. |
| 40 | |
| 41 | ## Declare the Website |
| 42 | |
| 43 | ```typescript |
| 44 | // alchemy.run.ts |
| 45 | import * as Railway from "@alchemy.run/railway"; |
| 46 | |
| 47 | export const Website = Railway.Website.Vinext("Website", { |
| 48 | rootDir: ".", |
| 49 | }); |
| 50 | ``` |
| 51 | |
| 52 | `rootDir`, `env`, `memo`, `assets`, `dev`, and `domain` use the same vocabulary |
| 53 | as the other Website constructors. Framework configuration stays in |
| 54 | `vite.config.ts` rather than a nested server configuration object. |
| 55 | |
| 56 | ## Add it to the Stack |
| 57 | |
| 58 | ```typescript |
| 59 | import * as Alchemy from "alchemy"; |
| 60 | import * as Effect from "effect/Effect"; |
| 61 | |
| 62 | export default Alchemy.Stack( |
| 63 | "MyVinextSite", |
| 64 | { providers: Railway.providers(), state: Alchemy.localState() }, |
| 65 | Effect.gen(function* () { |
| 66 | const site = yield* Website; |
| 67 | return { url: site.url }; |
| 68 | }), |
| 69 | ); |
| 70 | ``` |
| 71 | |
| 72 | Keep the local state available for subsequent deploys and teardown. |
| 73 | |
| 74 | ## Add environment variables |
| 75 | |
| 76 | ```typescript |
| 77 | export const Website = Railway.Website.Vinext("Website", { |
| 78 | env: { GREETING: "Hello from vinext on Railway!" }, |
| 79 | }); |
| 80 | ``` |
| 81 | |
| 82 | `env` is available during build, development, and production. Server code reads |
| 83 | `process.env`; public framework variables may be compiled into browser assets. |
| 84 | Keep secrets out of public keys and wrap credentials in `Redacted`. |
| 85 | |
| 86 | ## Read the runtime environment |
| 87 | |
| 88 | ```typescript |
| 89 | // app/api/hello/route.ts |
| 90 | export function GET(request: Request) { |
| 91 | const name = new URL(request.url).searchParams.get("name") ?? "world"; |
| 92 | return Response.json({ name, greeting: process.env.GREETING ?? "hello" }); |
| 93 | } |
| 94 | ``` |
| 95 | |
| 96 | Request-dependent route handlers read the production environment. A prerendered |
| 97 | page reflects its build-time inputs instead. |
| 98 | |
| 99 | ## Configure the data cache |
| 100 | |
| 101 | The default data cache is process-local. For shared, persistent ISR and |
| 102 | `"use cache"`, pass a `Railway.Redis` resource from the same project. Alchemy |
| 103 | binds `REDIS_URL`. Resources declared separately retain their own lifecycle in dev. |
| 104 | |
| 105 | ```typescript |
| 106 | const project = yield* Railway.Project("Project"); |
| 107 | const redis = yield* Railway.Redis("Cache", { project }); |
| 108 | const site = yield* Railway.Website.Vinext("Web", { project, redis }); |
| 109 | ``` |
| 110 | |
| 111 | ## Local development |
| 112 | |
| 113 | ```sh |
| 114 | bun alchemy dev |
| 115 | ``` |
| 116 | |
| 117 | The Website runs `vinext dev` with native HMR and creates no cloud resources. |
| 118 | Other resources declared in the Stack retain their own provider behavior. |
| 119 | Apply `.pipe(Alchemy.remote())` to the Website for a live deployment during dev. |
| 120 | |
| 121 | ## Custom domains |
| 122 | |
| 123 | ```typescript |
| 124 | const site = yield* Railway.Website.Vinext("Web", { |
| 125 | domain: "app.example.com", |
| 126 | }); |
| 127 | ``` |
| 128 | |
| 129 | See [Website domains](/railway/frontend/websites) for platform-specific DNS and |
| 130 | certificate configuration. |
| 131 | |
| 132 | ## Where next |
| 133 | |
| 134 | - [vinext API reference](/providers/railway/website/vinext). |
| 135 | - [Runnable example](https://github.com/alchemy-run/alchemy/tree/main/examples/railway-website-vinext). |
| 136 | - [Website overview](/railway/frontend/websites). |
| 137 | - [vinext on Cloudflare](/cloudflare/frontend/vinext) and [Prisma](/prisma/frontend/vinext). |