implement head requests

This commit is contained in:
Jonas Leder 2026-09-18 15:56:45 +02:00
commit bcc60f2637

View file

@ -37,26 +37,34 @@ func New(cfg config.Config, idx *index.Index, frontendFS fs.FS) (*Server, error)
return &Server{cfg: cfg, idx: idx, tmpl: tmpl, files: assets}, nil
}
const healthzPath = "/healthz"
// Engine builds and returns the configured gin.Engine.
func (s *Server) Engine() *gin.Engine {
gin.SetMode(s.cfg.GinMode)
r := gin.New()
r.Use(gin.Recovery(), gin.LoggerWithWriter(gin.DefaultWriter, "/healthz"))
r.Use(gin.Recovery(), gin.LoggerWithWriter(gin.DefaultWriter, healthzPath))
if s.cfg.FilesVHost != "" {
r.Use(s.vhostGuard)
}
r.GET("/healthz", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
healthz := func(c *gin.Context) { c.String(http.StatusOK, "ok") }
r.GET(healthzPath, healthz)
r.HEAD(healthzPath, healthz)
api := r.Group("/api")
{
api.GET("/dir", s.handleListDir)
api.HEAD("/dir", s.handleListDir)
api.GET("/search", s.handleSearch)
api.HEAD("/search", s.handleSearch)
api.GET("/stats", s.handleStats)
api.HEAD("/stats", s.handleStats)
}
r.GET("/files/*path", s.handleServeFile)
r.HEAD("/files/*path", s.handleServeFile)
r.StaticFS("/assets", http.FS(s.files))
@ -64,6 +72,7 @@ func (s *Server) Engine() *gin.Engine {
// window.location and drives navigation through the /api endpoints.
r.NoRoute(s.handleSPA)
r.GET("/", s.handleSPA)
r.HEAD("/", s.handleSPA)
return r
}