Update server configuration to disable serving frontend

This commit is contained in:
Mo Tarbin 2024-07-24 01:07:11 -04:00
parent 5cfb906a4f
commit a88946bb7f
7 changed files with 57 additions and 42 deletions

View file

@ -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) {
if h.ServeFrontend {
router.Use(staticMiddleware("dist"))
router.Static("/assets", "dist/assets")
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()
})
// Gzip compression middleware
router.Group("/assets").Use(func(c *gin.Context) {
c.Header("Cache-Control", "max-age=31536000, immutable")
c.Next()
})
}
}