Files
FFF_vtt_frozen/tools/serve.sh
T
SirStone 30b35592c7 fix: forward -- args through devbox scripts, fail serve loudly (#84)
devbox 0.17.2 runs .devbox/gen/scripts/<name>.sh with the args as positional
parameters but does not append "$@", so tools/serve.sh (and seed, bench,
mutation, import-scale, fogbench) saw an empty argv and a documented
`serve -- --image=...` silently served the default 4096 scene. End every
argument-taking script body with "$@".

serve: --dry-run parses and prints the options without building; unknown
options, non-numeric ports/tile sizes and --tile-size without --image fail
loudly; a no-image start prints the current map read from state.db; NixOS
gets security.pki.certificateFiles instead of the Debian trust steps.

Guard the faults import in worldmap/vision/markers with
`when defined(leakfault)` (it is only used inside those blocks), removing
the three UnusedImport warnings; leakfault builds still compile.

tools/devboxargs.test.mjs goes through `devbox run <script> -- <args>` for
serve (dry-run, unknown flag, tile-size without image) and seed (--help,
unknown flag), the seam the direct-tool tests missed.
2026-11-21 21:35:39 +01:00

47 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# devbox run serve (M4 #80): one command for a LAN playtest.
#
# Builds the server binary (run/fff-vtt) and the client dist (client/dist), then starts the
# TLS/HTTP2 nginx on the LAN address in front of the loopback server and blocks. Ctrl-C stops both
# processes. State, GM key and certificate live under the state dir (default run/lan) and are
# reused by the next run.
#
# devbox run serve # detected LAN IP, port 8443, state run/lan
# devbox run serve -- --image=run/map.png --tile-size=64
# devbox run serve -- --dry-run # print the parsed options, build nothing
# FFF_VTT_LAN_PORT=9443 devbox run serve
# FFF_VTT_STATE_DIR=run/lan2 devbox run serve
# FFF_VTT_LAN_HOST=192.168.1.50 devbox run serve # override the detected address
#
# `-- args` reach this script only because devbox.json appends "$@" to the script body (#84):
# devbox 0.17.2 runs the generated .devbox/gen/scripts/serve.sh with the args as positional
# parameters, but does not add "$@" itself. Keep that suffix in devbox.json.
set -euo pipefail
cd "$(dirname "$0")/.." || exit 1
# Parsing/validation and --help/--dry-run need no build. Run them before the expensive steps so a
# bad flag fails in milliseconds instead of after a Nim+client build.
for arg in "$@"; do
case "$arg" in
-h|--help|--dry-run) exec node tools/serve.mjs "$@" ;;
esac
done
STATE_DIR="${FFF_VTT_STATE_DIR:-run/lan}"
mkdir -p "$STATE_DIR" run
# Dependencies (idempotent) and the server binary. The worktree-local nimcache is deliberate: Nim's
# default cache is shared by every checkout, and two parallel worktrees corrupt each other.
nimble install -d -y
NIMBLE_PKGS="${NIMBLE_DIR:-.devbox/nimble}/pkgs2"
nim c --hints:off --mm:orc --nimblePath:"$NIMBLE_PKGS" \
--nimcache:run/nimcache/fff-vtt -o:run/fff-vtt server/main.nim
# The client build nginx serves at `/`.
( cd client
if [ ! -d node_modules ]; then npm ci --no-audit --no-fund; fi
npm run build
)
exec node tools/serve.mjs "$@"