Skip to content

Commit f860fd6

Browse files
committed
Config: support custom htpasswd path
1 parent 9b9cb55 commit f860fd6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mux.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,16 @@ func (s *Server) wrapMetricsAuth(f http.HandlerFunc) http.HandlerFunc {
6464
func NewHandler(server *Server) (http.Handler, error) {
6565
if !server.NoAuth {
6666
var err error
67-
server.htpasswdFile, err = NewHtpasswdFromFile(filepath.Join(server.Path, ".htpasswd"))
67+
htpasswd := server.Config.Auth.HTPasswdFile
68+
if htpasswd == "" {
69+
htpasswd = ".htpasswd"
70+
}
71+
if !filepath.IsAbs(htpasswd) {
72+
htpasswd = filepath.Join(server.Path, htpasswd)
73+
}
74+
server.htpasswdFile, err = NewHtpasswdFromFile(htpasswd)
6875
if err != nil {
69-
return nil, fmt.Errorf("cannot load .htpasswd (use --no-auth to disable): %v", err)
76+
return nil, fmt.Errorf("cannot load htpasswd file (use --no-auth to disable): %s: %v", htpasswd, err)
7077
}
7178
}
7279

0 commit comments

Comments
 (0)