forge
Explore
Log in

Don't you dare go Hollow

🔌 default the backend origin to the co-located loopback

Browse files at this commit

5f63fb5ccee64c836df3b616c93ae23d922dc477Ahmet Kaan GümüşParent: 5c869ed
  • fix
    • 🔌 default the backend origin to the co-located loopback
Show full message
fix: 🔌 default the backend origin to the co-located loopback
- server.ts and the vite dev proxy now default BACKEND_ORIGIN to
  http://127.0.0.1:7656 instead of the public origin — that is where the
  compose stack publishes the backend on this machine, and what the frontend
  container reaches under host networking
- nothing in a browser bundle changes: the SPA still calls its own origin and
  the server owns the backend address
- README: proxy note and the defaults list follow the new fallback
README.mdmodified+2 -2
@@ -51,7 +51,7 @@ bun run build
51 51
52 Open [http://localhost:5173](http://localhost:5173) in your browser.52 Open [http://localhost:5173](http://localhost:5173) in your browser.
53 53
54-> **Proxy Note**: Vite server and the production Bun server proxy `/api/*` and WebSocket connections to `BACKEND_ORIGIN` (default: `https://hezarfen.dizey.sh`), preserving HttpOnly session cookies across same-origin calls. Override it when needed: `BACKEND_ORIGIN=http://127.0.0.1:7656 bun run dev` against a local backend, or `BACKEND_ORIGIN` in `hezarfen_frontend.env` for the compose stack (see "Run in a container" below).54+> **Proxy Note**: Vite server and the production Bun server proxy `/api/*` and WebSocket connections to `BACKEND_ORIGIN` (default: `http://127.0.0.1:7656`, the co-located backend's loopback port), preserving HttpOnly session cookies across same-origin calls. Point it elsewhere with `BACKEND_ORIGIN=… bun run dev`, or with `BACKEND_ORIGIN` in `hezarfen_frontend.env` for the compose stack (see "Run in a container" below).
55 55
56 ---56 ---
57 57
@@ -65,7 +65,7 @@ podman compose down # stop
65 65
66 The `Containerfile` is a two-stage build: `bun install --frozen-lockfile` plus `bun run build` produce `dist/`, and `oven/bun:1-slim` serves it with `server.ts` — which also reverse-proxies `/api/*` (plain HTTP and the exam-room WebSocket) to `BACKEND_ORIGIN`. No nginx, no node_modules at runtime, no state: one container and no volumes. It runs with `network_mode: host`, so it shares the host's loopback and reaches a backend published on `127.0.0.1:7656` exactly as a host process would (a bridge network would resolve `127.0.0.1` to the container itself). Host networking means no port mapping: the app binds the host's interface directly, so set `HOST=127.0.0.1` and let the reverse proxy on the same loopback be the only door.66 The `Containerfile` is a two-stage build: `bun install --frozen-lockfile` plus `bun run build` produce `dist/`, and `oven/bun:1-slim` serves it with `server.ts` — which also reverse-proxies `/api/*` (plain HTTP and the exam-room WebSocket) to `BACKEND_ORIGIN`. No nginx, no node_modules at runtime, no state: one container and no volumes. It runs with `network_mode: host`, so it shares the host's loopback and reaches a backend published on `127.0.0.1:7656` exactly as a host process would (a bridge network would resolve `127.0.0.1` to the container itself). Host networking means no port mapping: the app binds the host's interface directly, so set `HOST=127.0.0.1` and let the reverse proxy on the same loopback be the only door.
67 67
68-**Knobs live in two places and are never mixed.** On a laptop nothing is required: with no env file the app falls back to its own defaults (`BACKEND_ORIGIN=https://hezarfen.dizey.sh`, `HOST=0.0.0.0`, `PORT=5173`), so the `up` above works with zero extra files. On a server the operator copies `deploy/hezarfen_frontend.env.example` to `$HOME/hezarfen_frontend/hezarfen_frontend.env`, `chmod 0600` it and edits it — nothing automated creates, overwrites or uploads that file. The service declares it as `env_file:`, so **every key it carries reaches the container with no extra flag**; nothing else is interpolated from it, and the only compose-level variable is `HEZARFEN_TAG`, which the deploy owns in `stack.env`.68+**Knobs live in two places and are never mixed.** On a laptop nothing is required: with no env file the app falls back to its own defaults (`BACKEND_ORIGIN=http://127.0.0.1:7656`, `HOST=0.0.0.0`, `PORT=5173`), so the `up` above works with zero extra files. On a server the operator copies `deploy/hezarfen_frontend.env.example` to `$HOME/hezarfen_frontend/hezarfen_frontend.env`, `chmod 0600` it and edits it — nothing automated creates, overwrites or uploads that file. The service declares it as `env_file:`, so **every key it carries reaches the container with no extra flag**; nothing else is interpolated from it, and the only compose-level variable is `HEZARFEN_TAG`, which the deploy owns in `stack.env`.
69 69
70 Environment values are read when the container **starts**: after editing the file, recreate (`podman compose up -d`, or `systemctl --user restart hezarfen_frontend_compose`). `podman restart` keeps the old environment.70 Environment values are read when the container **starts**: after editing the file, recreate (`podman compose up -d`, or `systemctl --user restart hezarfen_frontend_compose`). `podman restart` keeps the old environment.
71 71
server.tsmodified+5 -2
@@ -11,8 +11,11 @@ const PORT = Number(Bun.env.PORT ?? 5173);
11 // host networking the process sits directly on the host, so a server sets11 // host networking the process sits directly on the host, so a server sets
12 // HOST=127.0.0.1 and only the reverse proxy beside it can reach the app.12 // HOST=127.0.0.1 and only the reverse proxy beside it can reach the app.
13 const HOST = Bun.env.HOST ?? "0.0.0.0";13 const HOST = Bun.env.HOST ?? "0.0.0.0";
14-// Where the backend lives on the compose network. Override in compose.14+// Where the backend lives. The default is the co-located backend a server
15-const BACKEND_ORIGIN = Bun.env.BACKEND_ORIGIN ?? "https://hezarfen.dizey.sh";15+// publishes on its own loopback (the compose stack maps 127.0.0.1:7656), which
16+// is what the frontend container reaches under host networking. Override with
17+// BACKEND_ORIGIN for anything else.
18+const BACKEND_ORIGIN = Bun.env.BACKEND_ORIGIN ?? "http://127.0.0.1:7656";
16 const BACKEND_HTTP = BACKEND_ORIGIN.replace(/\/+$/, "");19 const BACKEND_HTTP = BACKEND_ORIGIN.replace(/\/+$/, "");
17 const BACKEND_WS = BACKEND_HTTP.replace(/^http/, "ws");20 const BACKEND_WS = BACKEND_HTTP.replace(/^http/, "ws");
18 const BACKEND_HOST = new URL(BACKEND_HTTP).host;21 const BACKEND_HOST = new URL(BACKEND_HTTP).host;
vite.config.tsmodified+1 -1
@@ -2,7 +2,7 @@ import path from "node:path";
2 import { defineConfig } from "vite";2 import { defineConfig } from "vite";
3 import solid from "vite-plugin-solid";3 import solid from "vite-plugin-solid";
4 4
5-const target = process.env.BACKEND_ORIGIN ?? "https://hezarfen.dizey.sh";5+const target = process.env.BACKEND_ORIGIN ?? "http://127.0.0.1:7656";
6 6
7 export default defineConfig({7 export default defineConfig({
8 plugins: [solid()],8 plugins: [solid()],