Add Cache-Control headers for static assets and versioned WASM/JS files in Gin server
This commit is contained in:
@@ -29,6 +29,20 @@ func SetupGinServer(ec *nats.EncodedConn, port string) *gin.Engine {
|
|||||||
// Recovery Middleware
|
// Recovery Middleware
|
||||||
r.Use(gin.Recovery())
|
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
|
// Health Check Endpoint
|
||||||
r.GET("/health", func(c *gin.Context) {
|
r.GET("/health", func(c *gin.Context) {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
|
|||||||
Reference in New Issue
Block a user