Repository navigation
fix(play): serve <build-dir>/index.html instead of 404ing the directory - #118
Merged
Merged
Conversation
Every game uploaded through the builds pipeline has entry_file = builds/<id>/index.html, so the SPA points frame.src at /play/<game>/builds/<id>/index.html. Go's http.ServeFile canonicalises any URL ending in "/index.html" with a 301 to the directory form — so "GET <build-dir>/" is the request that actually has to serve the game. #87's directory-listing guard 404'd every directory unconditionally: if fi, err := os.Stat(fullPath); err != nil || fi.IsDir() { c.String(http.StatusNotFound, "not found") That took every build-based game offline. Games whose entry_file is a bare index.html were unaffected, because the "/play/<id>/" form is rewritten to the entry file earlier in the handler — which is why this looked selective. The guard was merged weeks ago but only reached production in yesterday's rebuild (the running binary predated it by a month), so it presented as a regression from an unrelated deploy. Resolve a directory to its index.html before deriving any headers, so Content-Type, sandbox CSP, COOP, Permissions-Policy and cache rules are all computed from the file actually served. Directory listings stay blocked: a directory with no index.html is still a 404, and a bare directory is never handed to ServeFile. Verified against production game files: the exact failing request chain now returns 200 with the real game HTML, the sandbox CSP directive is intact, and builds/ still 404s. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The outage
Every game uploaded through the builds pipeline 404'd on launch in production.
entry_filefor those games isbuilds/<id>/index.html, so the SPA pointsframe.srcat/play/<game>/builds/<id>/index.html. Go'shttp.ServeFilecanonicalises any URL ending in
/index.htmlwith a 301 to the directory form —so
GET <build-dir>/is the request that actually has to serve the game:#87's directory-listing guard 404'd every directory unconditionally:
Games whose
entry_fileis a bareindex.htmlwere unaffected — the/play/<id>/form is rewritten to the entry file earlier in the handler(
games.go:897) — which is why this looked selective rather than total.Why it surfaced now: the guard merged weeks ago, but the running binary
predated it by a month. Yesterday's rebuild was the first time it ever executed,
so it presented as a regression from an unrelated deploy.
The fix
Resolve a directory to its
index.htmlbefore deriving any headers, soContent-Type, sandbox CSP, COOP, Permissions-Policy and cache rules are computed
from the file actually served. The guard's real purpose survives: a directory
with no
index.htmlis still a 404, and a bare directory is never handed toServeFile.Verification
Two regression tests in
internal/handlers/serve_index_test.go, confirmed tofail with the fix reverted (
got 404, want 200) and pass with it.Also ran the fixed binary against real production game files (DB snapshot +
read-only link to
data/games, isolated on port 8899):sandbox allow-scripts allow-pointer-lock allow-popups allow-forms allow-modalsintactbuilds/(no index.html) → still 404, no listing leakedNow deployed and confirmed live: every game returns 200 via
games.playmore.world, zero/play4xx since the restart.🤖 Generated with Claude Code