Try to enable caching

This commit is contained in:
Jan Bader 2021-12-07 21:32:20 +00:00
parent f4ddf12214
commit a19d3d6932

View File

@ -3,6 +3,7 @@ package http
import (
"io/fs"
"net/http"
"strings"
"git.javil.eu/jacob1123/budgeteer"
"git.javil.eu/jacob1123/budgeteer/bcrypt"
@ -39,6 +40,7 @@ func (h *Handler) Serve() {
if err != nil {
panic("couldn't open static files")
}
router.Use(headersByRequestURI())
router.StaticFS("/static", http.FS(static))
router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", nil) })
@ -83,3 +85,11 @@ func (h *Handler) Serve() {
router.Run(":1323")
}
func headersByRequestURI() gin.HandlerFunc {
return func(c *gin.Context) {
if strings.HasPrefix(c.Request.RequestURI, "/static/") {
c.Header("Cache-Control", "max-age=86400")
}
}
}