Commit e1018f91 authored by ale's avatar ale

Set up a parameterized shortlink redirector at /link/

parent 8ccbfd55
Pipeline #3572 passed with stages
in 1 minute and 1 second
......@@ -205,6 +205,7 @@ func makeServer() http.Handler {
})))
root.Handle("/service/{service}/details", withDynamicHeaders(http.HandlerFunc(handleServiceDetails)))
root.Handle("/service/{service}/container/{container}/details", withDynamicHeaders(http.HandlerFunc(handleContainerDetails)))
setupRedirects(root.PathPrefix("/link/").Subrouter())
root.Handle("/", withDynamicHeaders(http.HandlerFunc(handleIndex)))
return root
}
......
......@@ -6,11 +6,11 @@ import (
)
var sriMap = map[string]string{
"/static/js/bootstrap.bundle.min.js": "sha384-CS0nxkpPy+xUkNGhObAISrkg/xjb3USVCwy+0/NMzd5VxgY4CMCyTkItmy5n0voC",
"/static/js/jquery.slim.min.js": "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo",
"/static/css/bootstrap.min.css": "sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B",
"/static/css/open-iconic-bootstrap.min.css": "sha384-wWci3BOzr88l+HNsAtr3+e5bk9qh5KfjU6gl/rbzfTYdsAVHBEbxB33veLYmFg/a",
"/static/css/style.css": "sha384-OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb",
"/static/js/bootstrap.bundle.min.js": "sha384-CS0nxkpPy+xUkNGhObAISrkg/xjb3USVCwy+0/NMzd5VxgY4CMCyTkItmy5n0voC",
"/static/js/jquery.slim.min.js": "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo",
}
// SRIScript returns a <script> tag with resource integrity attributes.
......
......@@ -2,8 +2,11 @@ package main
import (
"fmt"
"net/http"
"net/url"
"strings"
"github.com/gorilla/mux"
)
// Constants for Kibana dashboard IDs.
......@@ -57,3 +60,28 @@ func grafanaQpsURL(vhost string) string {
"var-vhost": fmt.Sprintf("%s:443", vhost),
})
}
func redirHandler(f func(map[string]string) string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
http.Redirect(w, req, f(mux.Vars(req)), http.StatusFound)
})
}
// Set up some simple redirects to other services.
func setupRedirects(r *mux.Router) {
r.Handle("/program-logs/{program}", redirHandler(func(vars map[string]string) string {
return kibanaURL("syslog", fmt.Sprintf("program:\"%s\"", vars["program"]))
}))
r.Handle("/http-errors/{vhost}", redirHandler(func(vars map[string]string) string {
vhost := vars["vhost"]
if !strings.HasSuffix(vhost, ":443") {
vhost += ":443"
}
return kibanaURL("web", fmt.Sprintf("vhost:\"%s\" AND status:500", vhost))
}))
r.Handle("/accountserver/{user}", redirHandler(func(vars map[string]string) string {
return kibanaURL("syslog", fmt.Sprintf("program:accountserver AND \"%s\"", vars["user"]))
}))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment