Try to enable caching
This commit is contained in:
parent
f4ddf12214
commit
a19d3d6932
10
http/http.go
10
http/http.go
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user