From c1f057a15a8b4e5fbb8c8a608f9af290ff3cc79a Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Mon, 9 Oct 2023 10:51:38 -0700 Subject: [PATCH] make sure api calls are not cached in the desktop app. fixes #270 --- backend/pkg/web/middleware/cache.go | 11 +++++++++++ backend/pkg/web/server.go | 1 + 2 files changed, 12 insertions(+) create mode 100644 backend/pkg/web/middleware/cache.go diff --git a/backend/pkg/web/middleware/cache.go b/backend/pkg/web/middleware/cache.go new file mode 100644 index 000000000..5157a7153 --- /dev/null +++ b/backend/pkg/web/middleware/cache.go @@ -0,0 +1,11 @@ +package middleware + +import "github.com/gin-gonic/gin" + +func CacheMiddleware() gin.HandlerFunc { + return func(c *gin.Context) { + c.Writer.Header().Set("Cache-Control", "no-cache") + c.Writer.Header().Set("Pragma", "no-cache") + c.Next() + } +} diff --git a/backend/pkg/web/server.go b/backend/pkg/web/server.go index aa3669560..8847272b0 100644 --- a/backend/pkg/web/server.go +++ b/backend/pkg/web/server.go @@ -37,6 +37,7 @@ func (ae *AppEngine) Setup() (*gin.RouterGroup, *gin.Engine) { { api := base.Group("/api") { + api.Use(middleware.CacheMiddleware()) api.GET("/health", func(c *gin.Context) { //TODO: // check if the /web folder is populated.