Effect UI
Hetzner.Website.EffectUI deploys an Effect UI app to
Hetzner. It supports browser-only SPAs, server-side rendering (SSR), static
site generation (SSG), and hybrid rendering. HtmlServerVite.plugin in your
Vite config renders the pages and emits the handler; Alchemy packages them
for deployment.
Install
Section titled “Install”The build integration is not bundled with alchemy. Install
@alchemy.run/frontend-frameworks; the resource loads its /effect-ui
and /effect-ui/node exports from your project at deploy time. It is only
used at build time, so a dev dependency is enough:
pnpm add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00bun add -d https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00npm install -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00yarn add -D https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/9c58f00Effect UI is in public preview and isn’t on npm yet. Install a snapshot
build of @effect/ui as its
README describes.
Configure Vite
Section titled “Configure Vite”A browser-only app needs no plugin. Its Vite config stays what the Effect UI quick start gives you, and the build deploys as static files.
Render pages on the server
Section titled “Render pages on the server”Add HtmlServerVite.plugin and point it at a server entry. With
serverOutDir, the build also emits a request handler, which answers
every request that matches no file:
import { plugin as htmlServer } from "@effect/ui/html/HtmlServerVite";import { defineConfig } from "vite";
export default defineConfig({ build: { outDir: "dist/client" }, plugins: [ htmlServer({ entry: "/src/entry.server.ts", serverOutDir: "dist/server", }), ],});The server output must not overlap the client’s, so the client builds
to dist/client.
The server entry’s default export is a Layer that adds the app’s routes
to HttpRouter. prerender lists the pages the build renders ahead of
time. They are served as files, and the server renders everything else:
/// <reference types="@effect/ui/html/HtmlServerViteDocument" />import { layerHttp } from "@effect/ui/html/HtmlServerHttp";import { document } from "virtual:@effect/ui/document";import { App } from "./App.ts";import { AppRoute } from "./routes.ts";
export default layerHttp(App, { routes: AppRoute, document });
export const prerender = ["/about", "/404"];index.html marks where the page goes with <!--app-html-->. The
browser entry hydrates the server’s HTML instead of mounting a new app:
import { Router } from "@effect/ui";import { BrowserRouter, HtmlHydrate } from "@effect/ui/html";import { Effect, Layer } from "effect";import { App } from "./App.ts";import { AppRoute } from "./routes.ts";
const Main = HtmlHydrate.hydrate( App, Router.props(AppRoute), document.getElementById("app")!, JSON.parse(document.getElementById("state")!.textContent!),).pipe(Layer.provide(BrowserRouter.layer({ routes: AppRoute })));
Layer.launch(Main).pipe(Effect.runFork);Prerender without a server
Section titled “Prerender without a server”Leave serverOutDir out and the build keeps only the prerendered pages.
The site deploys as static files, and a prerendered /404 is the page
for paths that match nothing:
import { plugin as htmlServer } from "@effect/ui/html/HtmlServerVite";import { defineConfig } from "vite";
export default defineConfig({ plugins: [htmlServer({ entry: "/src/entry.server.ts" })],});Declare the Website
Section titled “Declare the Website”Declare the site as a module-level const (rather than inline in the Stack):
import * as Hetzner from "@alchemy.run/hetzner";
export const Website = Hetzner.Website.EffectUI("Website");For an app in a subdirectory of a monorepo, point rootDir at it:
export const Website = Hetzner.Website.EffectUI("Website", { rootDir: "applications/web",});Add it to the Stack
Section titled “Add it to the Stack”Yield the site from your Stack and return its URL:
import * as Alchemy from "alchemy";import * as Effect from "effect/Effect";
export default Alchemy.Stack( "MyEffectUISite", { providers: Hetzner.providers(), state: Alchemy.localState(), }, Effect.gen(function* () { const site = yield* Website; return { url: site.url }; }),);site.url is http://{ipv4}:3000. The site also exposes server
and service — they are undefined under alchemy dev.
Add environment variables
Section titled “Add environment variables”Set process environment variables through the top-level env map. Server
code reads private values from process.env; Vite inlines VITE_* values
into the browser build. Values must be strings or Redacted strings.
export const Website = Hetzner.Website.EffectUI("Website", { env: { API_BASE: "https://api.example.com", VITE_API_URL: "https://api.example.com", },});The values are copied onto process.env before Vite dev and build, and
onto the systemd unit. Server code reads process.env.API_BASE. Client code reads
import.meta.env.VITE_API_URL. Keep secrets out of VITE_* keys and the server-rendered
state; both reach the browser.
Read the environment in client code
Section titled “Read the environment in client code”Type a custom public key with Vite’s standard environment declaration:
/// <reference types="vite/client" />
interface ImportMetaEnv { readonly VITE_API_URL: string;}const apiUrl = import.meta.env.VITE_API_URL;Deep links
Section titled “Deep links”A browser-only app routes on the client, so a deep link like
/counter/42 arrives as a request for a file that doesn’t exist.
For browser-only builds, EffectUI defaults assets.notFoundHandling to
"single-page-application", which returns index.html (200) for
unmatched paths so the app’s router can resolve the route. Use
"404-page" to serve a real 404 instead:
export const Website = Hetzner.Website.EffectUI("Website", { assets: { notFoundHandling: "404-page" },});Local dev
Section titled “Local dev”alchemy dev runs the project’s Vite dev server, where HtmlServerVite
renders every page, instead of deploying; site.url is the local address and
no Server or Service is created. Wrap the site in Alchemy.remote()
to deploy the live unit even during dev.
Pin the dev server’s address when several apps run in one Stack:
export const Website = Hetzner.Website.EffectUI("Website", { dev: { host: "127.0.0.1", port: 5180, strictPort: true },});Custom domain
Section titled “Custom domain”domain requires an existing Hetzner.Zone
— v1 does not create one. Alchemy adds an A record pointing at the
Server’s public IPv4. url becomes http://{domain}:3000. There is
no TLS on the Service.
const site = yield* Hetzner.Website.EffectUI("Web", { domain: "app.example.com", zone,});