Skip to content

fix: make non-existent asset paths return a 404 #14472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: make non-existent asset paths return a 404
Before, if a file was not found we would serve the app.
  • Loading branch information
code-asher committed Aug 28, 2024
commit e6cc650af0bc7b5cedd57a0770a7b9d049b64d95
12 changes: 12 additions & 0 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
case reqFile == "bin" || strings.HasPrefix(reqFile, "bin/"):
h.handler.ServeHTTP(rw, r)
return
// If requesting assets, serve straight up with caching.
case reqFile == "assets" || strings.HasPrefix(reqFile, "assets/"):
// It could make sense to cache 404s, but the problem is that during an
// upgrade a load balance may route partially to the old server, and that
// would make new asset paths get cached as 404s and not load even once the
// new server was in place. To combat that, only cache if we have the file.
if h.exists(reqFile) && ShouldCacheFile(reqFile) {
rw.Header().Add("Cache-Control", "public, max-age=31536000, immutable")
}
// If the asset does not exist, this will return a 404.
h.handler.ServeHTTP(rw, r)
return
// If the original file path exists we serve it.
case h.exists(reqFile):
if ShouldCacheFile(reqFile) {
Expand Down
Loading