From a88946bb7fcfc1632661eafc84eac0aa1c2573c3 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Wed, 24 Jul 2024 01:07:11 -0400 Subject: Update server configuration to disable serving frontend --- frontend/handler.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'frontend') diff --git a/frontend/handler.go b/frontend/handler.go index 1a5337e..87ae17c 100644 --- a/frontend/handler.go +++ b/frontend/handler.go @@ -5,6 +5,7 @@ import ( "io/fs" "net/http" + "donetick.com/core/config" "github.com/gin-gonic/gin" ) @@ -12,22 +13,26 @@ import ( var embeddedFiles embed.FS type Handler struct { + ServeFrontend bool } -func NewHandler() *Handler { - return &Handler{} +func NewHandler(config *config.Config) *Handler { + return &Handler{ + ServeFrontend: config.Server.ServeFrontend, + } } func Routes(router *gin.Engine, h *Handler) { - - router.Use(staticMiddleware("dist")) - router.Static("/assets", "dist/assets") - - // Gzip compression middleware - router.Group("/assets").Use(func(c *gin.Context) { - c.Header("Cache-Control", "max-age=31536000, immutable") - c.Next() - }) + if h.ServeFrontend { + router.Use(staticMiddleware("dist")) + router.Static("/assets", "dist/assets") + + // Gzip compression middleware + router.Group("/assets").Use(func(c *gin.Context) { + c.Header("Cache-Control", "max-age=31536000, immutable") + c.Next() + }) + } } -- cgit