mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-30 15:22:07 +00:00
vmalert: properly form assets address if httpPrefix set (#4351)
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>
This commit is contained in:
parent
8ccdc6bf4f
commit
6be9416f6d
4 changed files with 82 additions and 77 deletions
|
@ -1,5 +1,4 @@
|
|||
{% import (
|
||||
"strings"
|
||||
"net/http"
|
||||
"path"
|
||||
"net/url"
|
||||
|
@ -76,10 +75,7 @@ type NavItem struct {
|
|||
|
||||
{% func printNavItems(r *http.Request, current string, items []NavItem) %}
|
||||
{%code
|
||||
prefix := "/vmalert/"
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
prefix = ""
|
||||
}
|
||||
prefix := utils.Prefix(r.URL.Path)
|
||||
%}
|
||||
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
|
||||
<div class="container-fluid">
|
||||
|
|
|
@ -9,52 +9,51 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
||||
)
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:10
|
||||
//line app/vmalert/tpl/header.qtpl:9
|
||||
import (
|
||||
qtio422016 "io"
|
||||
|
||||
qt422016 "github.com/valyala/quicktemplate"
|
||||
)
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:10
|
||||
//line app/vmalert/tpl/header.qtpl:9
|
||||
var (
|
||||
_ = qtio422016.Copy
|
||||
_ = qt422016.AcquireByteBuffer
|
||||
)
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:10
|
||||
//line app/vmalert/tpl/header.qtpl:9
|
||||
func StreamHeader(qw422016 *qt422016.Writer, r *http.Request, navItems []NavItem, title string) {
|
||||
//line app/vmalert/tpl/header.qtpl:10
|
||||
//line app/vmalert/tpl/header.qtpl:9
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:11
|
||||
//line app/vmalert/tpl/header.qtpl:10
|
||||
prefix := utils.Prefix(r.URL.Path)
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:11
|
||||
//line app/vmalert/tpl/header.qtpl:10
|
||||
qw422016.N().S(`
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>vmalert`)
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
//line app/vmalert/tpl/header.qtpl:14
|
||||
if title != "" {
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
//line app/vmalert/tpl/header.qtpl:14
|
||||
qw422016.N().S(` - `)
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
//line app/vmalert/tpl/header.qtpl:14
|
||||
qw422016.E().S(title)
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
//line app/vmalert/tpl/header.qtpl:14
|
||||
}
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
//line app/vmalert/tpl/header.qtpl:14
|
||||
qw422016.N().S(`</title>
|
||||
<link href="`)
|
||||
//line app/vmalert/tpl/header.qtpl:16
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
qw422016.E().S(prefix)
|
||||
//line app/vmalert/tpl/header.qtpl:16
|
||||
//line app/vmalert/tpl/header.qtpl:15
|
||||
qw422016.N().S(`static/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<style>
|
||||
body{
|
||||
|
@ -105,139 +104,136 @@ func StreamHeader(qw422016 *qt422016.Writer, r *http.Request, navItems []NavItem
|
|||
</head>
|
||||
<body>
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:65
|
||||
//line app/vmalert/tpl/header.qtpl:64
|
||||
streamprintNavItems(qw422016, r, title, navItems)
|
||||
//line app/vmalert/tpl/header.qtpl:65
|
||||
//line app/vmalert/tpl/header.qtpl:64
|
||||
qw422016.N().S(`
|
||||
<main class="px-2">
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
}
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
func WriteHeader(qq422016 qtio422016.Writer, r *http.Request, navItems []NavItem, title string) {
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
StreamHeader(qw422016, r, navItems, title)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
}
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
func Header(r *http.Request, navItems []NavItem, title string) string {
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
WriteHeader(qb422016, r, navItems, title)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
qs422016 := string(qb422016.B)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
return qs422016
|
||||
//line app/vmalert/tpl/header.qtpl:67
|
||||
//line app/vmalert/tpl/header.qtpl:66
|
||||
}
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:71
|
||||
//line app/vmalert/tpl/header.qtpl:70
|
||||
type NavItem struct {
|
||||
Name string
|
||||
Url string
|
||||
}
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:77
|
||||
//line app/vmalert/tpl/header.qtpl:76
|
||||
func streamprintNavItems(qw422016 *qt422016.Writer, r *http.Request, current string, items []NavItem) {
|
||||
//line app/vmalert/tpl/header.qtpl:77
|
||||
//line app/vmalert/tpl/header.qtpl:76
|
||||
qw422016.N().S(`
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:79
|
||||
prefix := "/vmalert/"
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
prefix = ""
|
||||
}
|
||||
//line app/vmalert/tpl/header.qtpl:78
|
||||
prefix := utils.Prefix(r.URL.Path)
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:83
|
||||
//line app/vmalert/tpl/header.qtpl:79
|
||||
qw422016.N().S(`
|
||||
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
|
||||
<div class="container-fluid">
|
||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-md-0">
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:88
|
||||
//line app/vmalert/tpl/header.qtpl:84
|
||||
for _, item := range items {
|
||||
//line app/vmalert/tpl/header.qtpl:88
|
||||
//line app/vmalert/tpl/header.qtpl:84
|
||||
qw422016.N().S(`
|
||||
<li class="nav-item">
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:91
|
||||
//line app/vmalert/tpl/header.qtpl:87
|
||||
u, _ := url.Parse(item.Url)
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:92
|
||||
//line app/vmalert/tpl/header.qtpl:88
|
||||
qw422016.N().S(`
|
||||
<a class="nav-link`)
|
||||
//line app/vmalert/tpl/header.qtpl:93
|
||||
//line app/vmalert/tpl/header.qtpl:89
|
||||
if current == item.Name {
|
||||
//line app/vmalert/tpl/header.qtpl:93
|
||||
//line app/vmalert/tpl/header.qtpl:89
|
||||
qw422016.N().S(` active`)
|
||||
//line app/vmalert/tpl/header.qtpl:93
|
||||
//line app/vmalert/tpl/header.qtpl:89
|
||||
}
|
||||
//line app/vmalert/tpl/header.qtpl:93
|
||||
//line app/vmalert/tpl/header.qtpl:89
|
||||
qw422016.N().S(`"
|
||||
href="`)
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
//line app/vmalert/tpl/header.qtpl:90
|
||||
if u.IsAbs() {
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
//line app/vmalert/tpl/header.qtpl:90
|
||||
qw422016.E().S(item.Url)
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
//line app/vmalert/tpl/header.qtpl:90
|
||||
} else {
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
//line app/vmalert/tpl/header.qtpl:90
|
||||
qw422016.E().S(path.Join(prefix, item.Url))
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
//line app/vmalert/tpl/header.qtpl:90
|
||||
}
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
//line app/vmalert/tpl/header.qtpl:90
|
||||
qw422016.N().S(`">
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:95
|
||||
//line app/vmalert/tpl/header.qtpl:91
|
||||
qw422016.E().S(item.Name)
|
||||
//line app/vmalert/tpl/header.qtpl:95
|
||||
//line app/vmalert/tpl/header.qtpl:91
|
||||
qw422016.N().S(`
|
||||
</a>
|
||||
</li>
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
}
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
//line app/vmalert/tpl/header.qtpl:94
|
||||
qw422016.N().S(`
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
`)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
}
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
func writeprintNavItems(qq422016 qtio422016.Writer, r *http.Request, current string, items []NavItem) {
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
streamprintNavItems(qw422016, r, current, items)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
}
|
||||
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
func printNavItems(r *http.Request, current string, items []NavItem) string {
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
writeprintNavItems(qb422016, r, current, items)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
qs422016 := string(qb422016.B)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
return qs422016
|
||||
//line app/vmalert/tpl/header.qtpl:102
|
||||
//line app/vmalert/tpl/header.qtpl:98
|
||||
}
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
package utils
|
||||
|
||||
import "strings"
|
||||
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 ""
|
||||
return pp
|
||||
}
|
||||
return prefix
|
||||
res, err := url.JoinPath(pp, prefix)
|
||||
if err != nil {
|
||||
return path
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ The following tip changes can be tested by building VictoriaMetrics components f
|
|||
|
||||
## v1.79.x long-time support release (LTS)
|
||||
|
||||
* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert.html): Properly form path to static assets in WEB UI if `http.pathPrefix` set. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4349).
|
||||
|
||||
## [v1.79.13](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.13)
|
||||
|
||||
Released at 2023-05-18
|
||||
|
|
Loading…
Reference in a new issue