feat(m4): LAN playtest run script (devbox run serve) (#80)

One command builds the client dist and server binary, then starts the
loopback server behind the DESIGN 11.1 TLS/HTTP2 nginx on the detected
LAN address. State, GM key and certificate persist under run/lan so a
table and a phone's trust survive Ctrl-C/restart; the certificate is
regenerated when the address changes. Prints the URL, GM key and
Android/laptop trust steps. tools/nginx.mjs and tools/tlsdev.mjs gained
the bind/SAN knobs the LAN needs (test defaults unchanged).
tools/serve.test.mjs proves h2 + verified TLS on /healthz and /, POST
/join, a /ws upgrade on the LAN address, loopback-only server binding,
and identical key/cert after a restart.
This commit is contained in:
2026-11-21 16:33:57 +01:00
parent ad610abd65
commit 356705823b
9 changed files with 593 additions and 37 deletions
+5 -5
View File
@@ -72,7 +72,7 @@ export async function startServer(opts = {}) {
const ownStateDir = opts.stateDir === undefined
const stateDir = opts.stateDir ?? makeStateDir()
const args = opts.args ?? []
const bin = buildServer({ defines: opts.defines })
const bin = opts.bin ?? buildServer({ defines: opts.defines })
const port = opts.port ?? await freePort()
const publicOrigin = opts.publicOrigin ?? baseUrl(port)
refuseLivePort(port)
@@ -130,8 +130,8 @@ const KEY_LINE = /GM key(?: \(new\))?: ([A-Z0-9-]+)/
// Runs `fff-vtt gm-key` against a state dir (the CLI is part of the product, so it is the source
// of the GM key in every harness).
export function runGmKey(stateDir, extra = []) {
const r = spawnSync(buildServer(), ['gm-key', `--state-dir=${stateDir}`, ...extra], { encoding: 'utf8' })
export function runGmKey(stateDir, extra = [], bin = buildServer()) {
const r = spawnSync(bin, ['gm-key', `--state-dir=${stateDir}`, ...extra], { encoding: 'utf8' })
return { status: r.status, stdout: r.stdout, stderr: r.stderr }
}
@@ -143,8 +143,8 @@ export function parseGmKey(stdout) {
}
// The GM key of a state dir, created on first call and stable afterwards.
export function gmKeyOf(stateDir) {
const r = runGmKey(stateDir)
export function gmKeyOf(stateDir, bin = buildServer()) {
const r = runGmKey(stateDir, [], bin)
if (r.status !== 0) throw new Error(`gm-key failed: ${r.stderr}`)
return parseGmKey(r.stdout)
}