Repository navigation
fix(server): serve /version on Lambda (excluded from static-path fallback) - #916
Conversation
…h fallback isStaticPath() only excluded /api/* and /health, so /version was falling through to the SPA file server on the Lambda Function URL path, returning index.html instead of the JSON build-metadata response added by PR #901. The HTTP/Cloud Run path was unaffected because mux.HandleFunc("/version", ...) is registered before the SPA catch-all in CreateHTTPServer. Add /version to the isStaticPath allowlist (same pattern as /health) so handleLambdaHTTPEvent routes it to app.API.HandleRequest, which already handles it correctly via the ExactPath:/version AuthPublic router entry. Also add test cases for /version and //version (double-slash normalised) to TestIsStaticPath.
|
@coderabbitai review |
📝 WalkthroughWalkthroughThe PR updates static-path routing logic to explicitly treat ChangesVersion Endpoint Routing
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/server/static_test.go (1)
97-98: 💤 Low valueConsider adding a trailing-slash test case for completeness.
The test cases correctly verify that
/versionand//versionare non-static. For more comprehensive coverage, consider adding{"/version/", false}to confirm thatpath.Clean("/version/")→"/version"also bypasses the SPA fallback.📋 Optional test case addition
{"/version", false}, // public build-metadata endpoint must reach API, not SPA {"//version", false}, // double-slash normalised to /version + {"/version/", false}, // trailing slash normalised to /version }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/server/static_test.go` around lines 97 - 98, Add a trailing-slash case to the static handler tests: update the test cases slice in internal/server/static_test.go (the table that currently contains {"/version", false} and {"//version", false}) to include {"/version/", false} so the test verifies path.Clean("/version/") → "/version" still bypasses the SPA fallback; ensure the new entry uses the same expected boolean and test logic as the other non-static cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/server/static_test.go`:
- Around line 97-98: Add a trailing-slash case to the static handler tests:
update the test cases slice in internal/server/static_test.go (the table that
currently contains {"/version", false} and {"//version", false}) to include
{"/version/", false} so the test verifies path.Clean("/version/") → "/version"
still bypasses the SPA fallback; ensure the new entry uses the same expected
boolean and test logic as the other non-static cases.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e1763440-febb-478d-b1e1-bc2254ddd7e2
📒 Files selected for processing (2)
internal/server/static.gointernal/server/static_test.go
Root cause
isStaticPath()ininternal/server/static.goonly excluded/api/*and/healthfrom the SPA file-server fallback./versionwas not in theallowlist, so on the Lambda Function URL path (
handleLambdaHTTPEvent) thecheck
isStaticPath("/version") == truecaused the request to be routed toserveLambdaStatic, which servedindex.htmlinstead of JSON.The HTTP / Cloud Run / Fargate path (
CreateHTTPServerininternal/server/http.go) was unaffected becausemux.HandleFunc("/version", app.handleVersion)is registered explicitly before the SPA catch-all handler,so the Go ServeMux routes it correctly regardless of
isStaticPath.The
/versionroute has been in the API router table since PR #901(
ExactPath: "/version",Auth: AuthPublic). OnceisStaticPath("/version")returns false,
app.API.HandleRequesthandles it correctly on the Lambda pathtoo.
Verified live before the fix:
Fix
Add
clean == "/version"to theisStaticPathallowlist using the samepattern as
/health. Updated the function doc comment to mention/versionasa public root-path endpoint and explain why it must bypass the SPA fallback.
Tests
Added two cases to
TestIsStaticPathininternal/server/static_test.go:{"/version", false}- direct path{"//version", false}- double-slash input normalised bypath.CleanAll 334 tests in
./internal/server/...pass.gofmtandgo vetclean.Notes
No issue to close - discovered during deploy debugging of the #901 build-version
diagnostic endpoint on a Lambda Function URL deployment. Behaviour is now
consistent across all deployment targets (Lambda, Cloud Run, Fargate).
Summary by CodeRabbit
/versionendpoint is properly directed to the API handler instead of incorrectly falling through to static content serving.