Skip to content

fix(play): serve <build-dir>/index.html instead of 404ing the directory - #118

Merged
yusufkaraaslan merged 1 commit into
mainfrom
fix/play-dir-index
Aug 11, 2026
Merged

yusufkaraaslan merged 1 commit into
mainfrom
fix/play-dir-index

Conversation

@yusufkaraaslan

Copy link
Copy Markdown
Owner

The outage

Every game uploaded through the builds pipeline 404'd on launch in production.

entry_file for those games is 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:

GET /play/<game>/builds/<build>/index.html  → 301   (Go canonicalisation, always happened)
GET /play/<game>/builds/<build>/            → 404   ← the guard below

#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")

Games whose entry_file is a bare index.html were 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.html before deriving any headers, so
Content-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.html is still a 404, and a bare directory is never handed to
ServeFile.

Verification

Two regression tests in internal/handlers/serve_index_test.go, confirmed to
fail 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):

  • both originally-failing games → 200, 4.4 MB of real game HTML
  • every build-based game in the DB → 200
  • sandbox allow-scripts allow-pointer-lock allow-popups allow-forms allow-modals intact
  • builds/ (no index.html) → still 404, no listing leaked

Now deployed and confirmed live: every game returns 200 via
games.playmore.world, zero /play 4xx since the restart.

🤖 Generated with Claude Code

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>
@yusufkaraaslan
yusufkaraaslan merged commit 0c6b448 into main Aug 11, 2026
2 checks passed
@yusufkaraaslan
yusufkaraaslan deleted the fix/play-dir-index branch August 11, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant