Private
Public Access
1
0

Add Cache-Control headers for static assets and versioned WASM/JS files in Gin server

This commit is contained in:
Sebastian Unterschütz
2026-01-06 18:46:48 +01:00
parent 291b6f5953
commit 2a635d0aaa

View File

@@ -29,6 +29,20 @@ func SetupGinServer(ec *nats.EncodedConn, port string) *gin.Engine {
// Recovery Middleware
r.Use(gin.Recovery())
// Cache Control Middleware für statische Assets
r.Use(func(c *gin.Context) {
path := c.Request.URL.Path
// Assets (Bilder, Fonts, etc.) - 1 Jahr cachen
if len(path) > 7 && path[:8] == "/assets/" {
c.Header("Cache-Control", "public, max-age=31536000, immutable")
}
// WASM und JS Dateien - nur cachen wenn mit ?v= Parameter
if (path == "/main.wasm" || path == "/game.js" || path == "/wasm_exec.js") && c.Query("v") != "" {
c.Header("Cache-Control", "public, max-age=31536000, immutable")
}
c.Next()
})
// Health Check Endpoint
r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{