feat: castle UX fixes from the lakehouse adoption test

Driven by adopting lakehouse (an existing daemon that bundles its own SPA) —
see docs/findings-lakehouse.md.

#3 deploy reloads the gateway. castle deploy regenerated the Caddyfile but
   left the running Caddy on the old config, so new proxy routes were silently
   dead. Deploy now reloads the gateway when it's running.

#1 castle expose <program>. Turns an adopted program into a service
   (run/port/health/proxy/systemd) in one command — the missing
   daemon-to-service step. Flags: --port --health --path --run --port-env
   --host --no-proxy.

#2 port_env mapping. A service can declare expose.http.internal.port_env so
   castle sets the env var the program actually reads (e.g. lakehoused reads
   LAKEHOUSED_DAEMON_PORT, not castle's convention LAKEHOUSE_PORT). Castle now
   genuinely drives an adopted daemon's bind port.

#4a auto-base for react-vite. The build passes VITE_BASE = the gateway serve
   prefix (/<name>/, or / for castle-app); vite.config reads it. A castle-built
   frontend now works at its subpath with no hand-tuned base. castle-app's
   vite.config updated as the reference.

#4b host-based routing. proxy.caddy.host routes a whole hostname to the backend
   root via a host matcher inside the :9000 site, so a root-based SPA (base="/")
   serves unchanged — the fix for proxying an app castle can't rebuild. Caddyfile
   now emits 'auto_https off' (HTTP-only gateway on a non-standard port).

Nit: activate skips the editable reinstall when the tool is already on PATH.

Tests: core 94, cli 24, api 52; ruff + app build clean. Verified live: lakehouse
runs under systemd, API at /lakehouse, full UI (SPA boots) via host routing.
This commit is contained in:
2026-06-14 13:16:34 -07:00
parent 203f5212e6
commit 4840cbe72a
12 changed files with 350 additions and 8 deletions

View File

@@ -56,6 +56,10 @@ import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
export default defineConfig({
// Castle sets VITE_BASE to the gateway serve prefix at build time (`/<name>/`,
// or `/` for the root app). Reading it here makes the bundle's absolute asset
// URLs resolve when served behind the gateway at a subpath — no hand-tuning.
base: process.env.VITE_BASE ?? "/",
plugins: [react(), tailwindcss()],
resolve: {
alias: {
@@ -65,6 +69,12 @@ export default defineConfig({
})
```
> **Serving behind the gateway.** A static frontend mounts at `/<name>/` (the
> root `castle-app` at `/`). Castle's `react-vite` build passes that prefix as
> `VITE_BASE`, so a frontend that reads it (above) works at its subpath with no
> manual `base`. Frontends that don't read `VITE_BASE` must hand-set `base` to
> match, or they'll request assets from the wrong path.
## Project layout
```