Skip to content

refactor(server): extract shared handler construction (#38)#50

Merged
jacaudi merged 1 commit into
mainfrom
fix/go-handler-refactor
Apr 11, 2026
Merged

refactor(server): extract shared handler construction (#38)#50
jacaudi merged 1 commit into
mainfrom
fix/go-handler-refactor

Conversation

@jacaudi

@jacaudi jacaudi commented Apr 11, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the Go portion of #38. server/main.go and server/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 real server behaved differently.

  • Extract buildHandler(indexContent string) http.Handler in server/main.go — single source of truth for headers, CSP, cache routing.
  • Extract prepareIndexContent(appFS fs.FS) (string, error) — handles __APP_VERSION__ and FK_DEBUG substitution. Env is read at call time so t.Setenv still works.
  • main() and makeHandler() both delegate to these functions.
  • main_test.go collapses 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 build all clean
  • CI green

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>
@jacaudi jacaudi merged commit be3e8bf into main Apr 11, 2026
13 checks passed
@jacaudi jacaudi deleted the fix/go-handler-refactor branch April 11, 2026 07:11
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