| 1 | --- |
| 2 | title: Vinext |
| 3 | description: Deploy vinext to Hetzner with the shared Website API, native local development, and a platform-specific data cache. |
| 4 | sidebar: |
| 5 | order: 9.6 |
| 6 | --- |
| 7 | |
| 8 | import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks"; |
| 11 | |
| 12 | `Hetzner.Website.Vinext` builds with the Vinext Vite API for production and runs native |
| 13 | `vinext dev` locally. The built app runs on a Hetzner Cloud Server using vinext's production Node |
| 14 | server as a systemd service. Alchemy creates a server when `server` is omitted |
| 15 | and uploads `dist/` with the runtime dependency installation. |
| 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 | <Tabs syncKey="pkgManager"> |
| 24 | <TabItem label="bun" icon="bun"><Code code={`bun add -d ${devDeps}`} lang="sh" /></TabItem> |
| 25 | <TabItem label="npm" icon="npm"><Code code={`npm install -D ${devDeps}`} lang="sh" /></TabItem> |
| 26 | <TabItem label="pnpm" icon="pnpm"><Code code={`pnpm add -D ${devDeps}`} lang="sh" /></TabItem> |
| 27 | <TabItem label="yarn" icon="seti:yarn"><Code code={`yarn add -D ${devDeps}`} lang="sh" /></TabItem> |
| 28 | </Tabs> |
| 29 | |
| 30 | ## Configure vinext |
| 31 | |
| 32 | ```typescript |
| 33 | // vite.config.ts |
| 34 | import { defineConfig } from "vite"; |
| 35 | import vinext from "vinext"; |
| 36 | |
| 37 | export default defineConfig({ |
| 38 | plugins: [vinext({ prerender: true })], |
| 39 | }); |
| 40 | ``` |
| 41 | |
| 42 | Alchemy injects the target-specific data-cache adapter during deployment. |
| 43 | No Alchemy plugin is required in `vite.config.ts`; deployment settings belong on |
| 44 | `Website.Vinext`. Leave Cloudflare plugins and Worker entrypoints out of this application. |
| 45 | |
| 46 | ## Declare the Website |
| 47 | |
| 48 | ```typescript |
| 49 | // alchemy.run.ts |
| 50 | import * as Hetzner from "alchemy/Hetzner"; |
| 51 | |
| 52 | export const Website = Hetzner.Website.Vinext("Website", { |
| 53 | rootDir: ".", |
| 54 | }); |
| 55 | ``` |
| 56 | |
| 57 | `rootDir`, `env`, `memo`, `assets`, `dev`, and `domain` use the same vocabulary |
| 58 | as the other Website constructors. Framework configuration stays in |
| 59 | `vite.config.ts` rather than a nested server configuration object. |
| 60 | |
| 61 | ## Add it to the Stack |
| 62 | |
| 63 | ```typescript |
| 64 | import * as Alchemy from "alchemy"; |
| 65 | import * as Effect from "effect/Effect"; |
| 66 | |
| 67 | export default Alchemy.Stack( |
| 68 | "MyVinextSite", |
| 69 | { providers: Hetzner.providers(), state: Alchemy.localState() }, |
| 70 | Effect.gen(function* () { |
| 71 | const site = yield* Website; |
| 72 | return { url: site.url }; |
| 73 | }), |
| 74 | ); |
| 75 | ``` |
| 76 | |
| 77 | Keep the local state available for subsequent deploys and teardown. |
| 78 | |
| 79 | ## Add environment variables |
| 80 | |
| 81 | ```typescript |
| 82 | export const Website = Hetzner.Website.Vinext("Website", { |
| 83 | env: { GREETING: "Hello from vinext on Hetzner!" }, |
| 84 | }); |
| 85 | ``` |
| 86 | |
| 87 | `env` is available during build, development, and production. Server code reads |
| 88 | `process.env`; public framework variables may be compiled into browser assets. |
| 89 | Keep secrets out of public keys and wrap credentials in `Redacted`. |
| 90 | |
| 91 | ## Read the runtime environment |
| 92 | |
| 93 | ```typescript |
| 94 | // app/api/hello/route.ts |
| 95 | export function GET(request: Request) { |
| 96 | const name = new URL(request.url).searchParams.get("name") ?? "world"; |
| 97 | return Response.json({ name, greeting: process.env.GREETING ?? "hello" }); |
| 98 | } |
| 99 | ``` |
| 100 | |
| 101 | Request-dependent route handlers read the production environment. A prerendered |
| 102 | page reflects its build-time inputs instead. |
| 103 | |
| 104 | ## Configure the data cache |
| 105 | |
| 106 | The default data cache is process-local. To persist ISR and `"use cache"` |
| 107 | across restarts, supply an existing Redis endpoint through `env.REDIS_URL`. |
| 108 | The Website does not install or provision Redis. Protect credentials with |
| 109 | `Redacted.make` and keep the Redis service private. |
| 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* Hetzner.Website.Vinext("Web", { |
| 125 | domain: "app.example.com", |
| 126 | zone, |
| 127 | }); |
| 128 | ``` |
| 129 | |
| 130 | Hetzner requires an existing DNS `zone` when setting `domain`. |
| 131 | See [Website domains](/hetzner/frontend/websites) for platform-specific DNS and |
| 132 | certificate configuration. |
| 133 | |
| 134 | ## Where next |
| 135 | |
| 136 | - [vinext API reference](/providers/hetzner/website/vinext). |
| 137 | - [Runnable example](https://github.com/alchemy-run/alchemy/tree/main/examples/hetzner-website-vinext). |
| 138 | - [Website overview](/hetzner/frontend/websites). |
| 139 | - [vinext on Cloudflare](/cloudflare/frontend/vinext) and [Prisma](/prisma/frontend/vinext). |