Skip to content

Answer missing files with 404 instead of the index page - #3

Merged
hami9 merged 1 commit into
mainfrom
fix/static-web-404
Sep 30, 2026
Merged

hami9 merged 1 commit into
mainfrom
fix/static-web-404

Conversation

@hami9

@hami9 hami9 commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Found while testing v1.4.0 on a Galaxy S9. The static web server answered every unknown path with the entrypoint, so a missing asset came back as HTML with a 200:

GET /style.css    -> 200  text/css          (real file)
GET /missing.css  -> 200  text/html   <-- the index page
GET /nope.txt     -> 200  text/html   <-- the index page

A typo in an asset path broke the page silently. The SPA fallback is still right for routes (/dashboard), so it now applies only when the last path segment has no extension; anything that names a file resolves to that file, and a file that does not exist becomes a 404.

Path traversal still returns 403, HEAD still works, and non-GET/HEAD still returns 405 — unchanged.

New StaticWebRoutingTest locks in: entrypoint for / and for extension-less routes, real files for real paths, a non-existent file for /missing.css and /assets/nope.js, and null for paths escaping the source folder.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Missing requests for file paths now return a 404 instead of displaying the app’s entrypoint. Extensionless routes continue to load the entrypoint, and paths outside the web directory are refused.
  • Tests

    • Added coverage for root routing, existing files, extensionless routes, missing files, and paths outside the web directory.

The static web server sent the entrypoint for every path it could not
find, so a request for a file that does not exist came back as the HTML
page with a 200. Tested on a phone against the Static Website template:

    GET /missing.css  ->  200, Content-Type: text/html

A typo in a stylesheet or script path therefore broke the page with no
error anywhere. The single-page-app fallback is worth keeping for routes
like /dashboard, so it now applies only to paths whose last segment has
no extension. A path that names a file resolves to that file, and the
caller turns a file that does not exist into a 404.

Covered by StaticWebRoutingTest: the entrypoint for / and for routes,
real files for real paths, a missing file for /missing.css and
/assets/nope.js, and null (403) for paths that escape the source folder.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 272de1d4-08e5-4119-a064-a180e1918321

📥 Commits

Reviewing files that changed from the base of the PR and between ca765da and 159ced3.

📒 Files selected for processing (2)
  • app/src/main/java/com/runcode/app/runtime/StaticWebEngine.kt
  • app/src/test/java/com/runcode/app/runtime/StaticWebRoutingTest.kt
 _________________________________________
< Digging deeper than a Minecraft player. >
 -----------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@hami9
hami9 merged commit f5cce4e into main Sep 30, 2026
1 of 2 checks passed
@hami9
hami9 deleted the fix/static-web-404 branch September 30, 2026 10:23
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