Skip to content

Commit cd38e29

Browse files
authored
fix: make non-existent asset paths return a 404 (#14472)
Before, if a file was not found we would serve the app. This would cause either the login page or the workspace page to load (and consequently error because `assets` is likely not a valid user).
1 parent ef7fcf3 commit cd38e29

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

site/site.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
205205
case reqFile == "bin" || strings.HasPrefix(reqFile, "bin/"):
206206
h.handler.ServeHTTP(rw, r)
207207
return
208+
// If requesting assets, serve straight up with caching.
209+
case reqFile == "assets" || strings.HasPrefix(reqFile, "assets/"):
210+
// It could make sense to cache 404s, but the problem is that during an
211+
// upgrade a load balancer may route partially to the old server, and that
212+
// would make new asset paths get cached as 404s and not load even once the
213+
// new server was in place. To combat that, only cache if we have the file.
214+
if h.exists(reqFile) && ShouldCacheFile(reqFile) {
215+
rw.Header().Add("Cache-Control", "public, max-age=31536000, immutable")
216+
}
217+
// If the asset does not exist, this will return a 404.
218+
h.handler.ServeHTTP(rw, r)
219+
return
208220
// If the original file path exists we serve it.
209221
case h.exists(reqFile):
210222
if ShouldCacheFile(reqFile) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy