speed + more config

This commit is contained in:
JurajKubrican
2025-08-04 20:24:57 +02:00
parent c350501f29
commit db8fd17376
7 changed files with 35 additions and 12 deletions

View File

@@ -3,6 +3,9 @@ package main
import (
"html/template"
"io"
"net/http"
"strings"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
@@ -47,9 +50,21 @@ func main() {
e.Logger.SetLevel(log.DEBUG)
e.Use(middleware.Logger())
e.Use(middleware.Gzip())
e.Use(middleware.HTTPSRedirect())
e.GET("/health", healthCheck)
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if strings.HasPrefix(c.Request().URL.Path, "/css/") || strings.HasPrefix(c.Request().URL.Path, "/js/") {
c.Response().Header().Set("Cache-Control", "public, max-age=31536000") // 1 year
c.Response().Header().Set("Expires", time.Now().AddDate(1, 0, 0).Format(http.TimeFormat))
}
return next(c)
}
})
e.Static("/css", "css")
e.Static("/js", "js")