refactor(server): extract shared handler construction (#38)#50
Merged
Conversation
Both main.go and main_test.go duplicated the security headers, CSP policy, FK_DEBUG replacement, and route registration logic. If one diverged from the other, tests could pass while the server behaved differently. Extract the routing/headers into buildHandler(indexContent) and the index-content preparation into prepareIndexContent(appFS). main() and the test helper now both call these, so there is a single source of truth for observable server behavior. No observable behavior changes: all existing Go tests pass unmodified. Co-Authored-By: Claude Opus 4.6 <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.
Summary
Fixes the Go portion of #38.
server/main.goandserver/main_test.goduplicated the security headers, CSP policy,FK_DEBUGreplacement, and route-registration logic. If one diverged from the other, tests could pass while the real server behaved differently.buildHandler(indexContent string) http.Handlerinserver/main.go— single source of truth for headers, CSP, cache routing.prepareIndexContent(appFS fs.FS) (string, error)— handles__APP_VERSION__andFK_DEBUGsubstitution. Env is read at call time sot.Setenvstill works.main()andmakeHandler()both delegate to these functions.main_test.gocollapses from ~50 to ~10 lines.Diff:
server/main.go+34/-11,server/main_test.go+4/-43. No behavior changes.Partial fix for #38 — the build-script comment-stripping portion is handled by #fix/build-comment-stripper.
Test plan
go test ./...— all tests pass (TestVersionInjection, TestCacheControlHeaders, TestSecurityHeaders, TestCSPHeader, TestEmbeddedFiles, TestFKDebugInjection, TestFKDebugEnabled + subtests)go vet,gofmt -l,go buildall clean