aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/middleware.go
blob: 90560faecdcf4cf2775f119aafb1eaa6449119dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package admin

import (
	"log/slog"
	"net/http"
)

// Hooks middleware to handle requests to the admin repo.
func Hooks(adminSvc *Servicer, next http.Handler) http.Handler {
	repoUpdatePath := "/mgmt/git-receive-pack"
	return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		next.ServeHTTP(rw, req)
		slog.Debug("hooks middleware", "url", req.URL.Path)
		if req.URL.Path == repoUpdatePath && req.Method == http.MethodPost {
			slog.Debug("hook firing reload")
			go adminSvc.Reload()
		}
	})
}