mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
6e02885431
Properly form path to static assets in WEB UI
if `http.pathPrefix` set.
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4349
Signed-off-by: hagen1778 <roman@victoriametrics.com>
(cherry picked from commit 51cea6cad4
)
Signed-off-by: hagen1778 <roman@victoriametrics.com>
24 lines
448 B
Go
24 lines
448 B
Go
package utils
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
|
)
|
|
|
|
const prefix = "/vmalert/"
|
|
|
|
// Prefix returns "/vmalert/" prefix if it is missing in the path.
|
|
func Prefix(path string) string {
|
|
pp := httpserver.GetPathPrefix()
|
|
path = strings.TrimLeft(path, pp)
|
|
if strings.HasPrefix(path, prefix) {
|
|
return pp
|
|
}
|
|
res, err := url.JoinPath(pp, prefix)
|
|
if err != nil {
|
|
return path
|
|
}
|
|
return res
|
|
}
|