mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
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).
This commit is contained in:
12
site/site.go
12
site/site.go
@ -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 balancer 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) {
|
||||
|
Reference in New Issue
Block a user