Skip to content
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

Add cache-control headers to dashboard static assets #165

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion build/package/Dockerfile.dashboard
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WORKDIR /dashboard-ui

# enable pnpm
RUN corepack enable
RUN corepack prepare pnpm@latest --activate
RUN corepack prepare pnpm@9.14.2 --activate

# fetch dependencies
COPY dashboard-ui/package.json ./
Expand Down
5 changes: 4 additions & 1 deletion modules/dashboard/pkg/app/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
zlog "github.com/rs/zerolog/log"

"github.com/kubetail-org/kubetail/modules/shared/config"
"github.com/kubetail-org/kubetail/modules/shared/middleware"
)

type websiteHandlers struct {
Expand All @@ -40,7 +41,9 @@ func (app *websiteHandlers) InitStaticHandlers(root *gin.RouterGroup) {

// add assets directory
if assetsFS, err := fs.Sub(app.websiteFS, "assets"); err == nil {
root.StaticFS("/assets", http.FS(assetsFS))
assetsGroup := root.Group("/assets")
assetsGroup.Use(middleware.CacheControlMiddleware)
assetsGroup.StaticFS("/", http.FS(assetsFS))
}
}

Expand Down
6 changes: 6 additions & 0 deletions modules/shared/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ func LoggingMiddleware(hideHealthChecks bool) gin.HandlerFunc {
m.Send()
}
}

// Add far-future expires cache headers
func CacheControlMiddleware(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
c.Next()
}