fix(server): strip leading slash in serveStatic for absolute webDistPath#1047
Conversation
Hono's serveStatic passes c.req.path (e.g. '/assets/foo.js') to path.join with the root. When root is absolute, path.join treats the leading slash as an absolute segment and discards root entirely. Add rewriteRequestPath to strip the leading slash so the full path resolves correctly.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdded a production-time check logging Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Review SummaryReviewed by 5 specialized agents: code-reviewer, docs-impact, silent-failure-hunter, comment-analyzer, code-simplifier. Scope includes PR #1047 diff + latest dev commit Critical Issues (1 found)
Evidence: Traced through Hono source ( Important Issues (2 found)
Suggestions (2 found)
Strengths
Recommended Actions
VerdictNEEDS INVESTIGATION — The core premise of the PR (that |
…ess.once - Remove stripLeadingSlash — Bun's path.join handles leading slashes correctly - Add existsSync check on webDistPath at startup with log.warn - Switch process.on to process.once for signal handlers in serve.ts - Keep favicon.png explicit route (useful addition)
fix(server): strip leading slash in serveStatic for absolute webDistPath
fix(server): strip leading slash in serveStatic for absolute webDistPath
Summary
serveStaticpassesc.req.path(e.g./assets/foo.js) topath.joinwith therootoption. Whenrootis an absolute path (like~/.archon/web-dist/0.3.4),path.jointreats the leading/in the request path as an absolute segment and discards the root entirely — resolving to/assets/foo.jsinstead of~/.archon/web-dist/0.3.4/assets/foo.jsarchon servedownloads the web UI to an absolute path, so all static files (CSS, JS, favicon) fail to load — the web UI shows a blank pagerewriteRequestPathto strip the leading slash beforepath.join, and an explicit/favicon.pngrouteindex.html) already worked because it usespath: 'index.html'(relative, no leading slash). API routes unaffected.UX Journey
Before
After
Label Snapshot
risk: lowsize: XSserverserver:static-servingChange Metadata
bugserverValidation Evidence (required)
Tested in production mode with built web dist:
Security Impact (required)
NoNoNoNoCompatibility / Migration
YesNoNoHuman Verification (required)
/chatreturnsindex.htmlSide Effects / Blast Radius (required)
Rollback Plan (required)
git revert <commit>Risks and Mitigations
rewriteRequestPathmight affect other Hono middleware/assets/*route, scoped narrowlySummary by CodeRabbit