Skip to content

Serve a proper 404 error page for missing static files - #426

Open
bauerpawel wants to merge 1 commit into
Forceu:masterfrom
bauerpawel:feat/static-404-page
Open

bauerpawel wants to merge 1 commit into
Forceu:masterfrom
bauerpawel:feat/static-404-page

Conversation

@bauerpawel

Copy link
Copy Markdown
Contributor

Description

Requests for a static asset that doesn't exist (e.g. a stale/mistyped JS or CSS path) previously fell through http.FileServer to the plain stdlib 404 response instead of Gokapi's own styled error page.

Intercepts the http.FileServer response via a small http.ResponseWriter wrapper: if it would write a 404, the cache headers that were speculatively set for the (assumed-existing) file are removed and the request is redirected to Gokapi's existing generic error page (errorHandling.RedirectGenericErrorPage with TypeFileNotFound) instead.

Type of Change

  • New feature (non-breaking change which adds functionality)

Technical Details

  • Database changes: No
  • Storage backend affected: No
  • Usage of AI: Yes — developed with Claude Code as a pair-programming assistant. I reviewed and tested all changes before submitting.

How Has This Been Tested?

  • Unit Tests: go test ./internal/webserver/... --tags=test,awsmock and full go test ./... --tags=test,awsmock suite pass; added TestStaticFileNotFound covering the new redirect behavior.
  • Environment: Windows 11

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation. (n/a — internal error-page behavior, no user-facing docs affected)
  • My changes generate no new warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_0168YUwGEzEHTqd9CwzXE53d

http.FileServer previously fell through to the default net/http 404
response for unmatched static-asset requests. Intercepts that response
and redirects to Gokapi's own styled error page instead, undoing the
cache headers that were speculatively set for the (nonexistent) file
first.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0168YUwGEzEHTqd9CwzXE53d
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