mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-01 02:52:06 +00:00
Merge pull request #847 from mxinden/serve-libs
Serve FontAwesome & Bootstrap ourself
This commit is contained in:
commit
d383ab0d91
7
Makefile
7
Makefile
@ -60,7 +60,12 @@ assets:
|
||||
-@$(GO) get -u github.com/jteeuwen/go-bindata/...
|
||||
# Using "-mode 420" and "-modtime 1" to make assets make target deterministic.
|
||||
# It sets all file permissions and time stamps to 420 and 1
|
||||
@go-bindata $(bindata_flags) -mode 420 -modtime 1 -pkg ui -o ui/bindata.go ui/app/script.js ui/app/index.html ui/app/favicon.ico
|
||||
@go-bindata $(bindata_flags) -mode 420 -modtime 1 -pkg ui -o \
|
||||
ui/bindata.go ui/app/script.js \
|
||||
ui/app/index.html \
|
||||
ui/app/favicon.ico \
|
||||
ui/lib/...
|
||||
|
||||
@go-bindata $(bindata_flags) -mode 420 -modtime 1 -pkg deftmpl -o template/internal/deftmpl/bindata.go template/default.tmpl
|
||||
|
||||
promu:
|
||||
|
@ -4,8 +4,6 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Alertmanager</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
|
||||
<script src="https://use.fontawesome.com/b7508bb100.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
@ -66,7 +66,13 @@ init flags location =
|
||||
if prod then
|
||||
Api.makeApiUrl location.pathname
|
||||
else
|
||||
Api.makeApiUrl "http://localhost:9093"
|
||||
Api.makeApiUrl "http://localhost:9093/"
|
||||
|
||||
libUrl =
|
||||
if prod then
|
||||
location.pathname
|
||||
else
|
||||
"http://localhost:9093/"
|
||||
in
|
||||
update (urlUpdate location)
|
||||
(Model
|
||||
@ -79,6 +85,8 @@ init flags location =
|
||||
initStatusModel
|
||||
location.pathname
|
||||
apiUrl
|
||||
libUrl
|
||||
Loading
|
||||
Loading
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,9 @@ type alias Model =
|
||||
, status : StatusModel
|
||||
, basePath : String
|
||||
, apiUrl : String
|
||||
, libUrl : String
|
||||
, bootstrapCSS : ApiData String
|
||||
, fontAwesomeCSS : ApiData String
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +44,7 @@ type Msg
|
||||
| RedirectAlerts
|
||||
| UpdateFilter String
|
||||
| BootstrapCSSLoaded (ApiData String)
|
||||
| FontAwesomeCSSLoaded (ApiData String)
|
||||
|
||||
|
||||
type Route
|
||||
|
@ -129,3 +129,6 @@ update msg ({ basePath, apiUrl } as model) =
|
||||
|
||||
BootstrapCSSLoaded css ->
|
||||
( { model | bootstrapCSS = css }, Cmd.none )
|
||||
|
||||
FontAwesomeCSSLoaded css ->
|
||||
( { model | fontAwesomeCSS = css }, Cmd.none )
|
||||
|
@ -4,7 +4,7 @@ import Html exposing (Html, node, text, div)
|
||||
import Html.Attributes exposing (class, rel, href, src, style)
|
||||
import Html.Events exposing (on)
|
||||
import Json.Decode exposing (succeed)
|
||||
import Types exposing (Msg(MsgForSilenceForm, MsgForSilenceView, BootstrapCSSLoaded), Model, Route(..))
|
||||
import Types exposing (Msg(MsgForSilenceForm, MsgForSilenceView, BootstrapCSSLoaded, FontAwesomeCSSLoaded), Model, Route(..))
|
||||
import Utils.Views exposing (error, loading)
|
||||
import Utils.Types exposing (ApiData(Failure, Success))
|
||||
import Views.SilenceList.Views as SilenceList
|
||||
@ -19,42 +19,49 @@ import Views.NavBar.Views exposing (navBar)
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ renderLink "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"
|
||||
, fontAwesome
|
||||
, case model.bootstrapCSS of
|
||||
Success _ ->
|
||||
[ renderCSS model.libUrl
|
||||
, case ( model.bootstrapCSS, model.fontAwesomeCSS ) of
|
||||
( Success _, Success _ ) ->
|
||||
div []
|
||||
[ navBar model.route
|
||||
, div [ class "container pb-4" ] [ currentView model ]
|
||||
]
|
||||
|
||||
Failure err ->
|
||||
div []
|
||||
[ div [ style [ ( "padding", "40px" ), ( "color", "red" ) ] ] [ text err ]
|
||||
, navBar model.route
|
||||
, div [ class "container pb-4" ] [ currentView model ]
|
||||
]
|
||||
( Failure err, _ ) ->
|
||||
failureView model err
|
||||
|
||||
( _, Failure err ) ->
|
||||
failureView model err
|
||||
|
||||
_ ->
|
||||
text ""
|
||||
]
|
||||
|
||||
|
||||
renderLink : String -> Html Msg
|
||||
renderLink url =
|
||||
failureView : Model -> String -> Html Msg
|
||||
failureView model err =
|
||||
div []
|
||||
[ div [ style [ ( "padding", "40px" ), ( "color", "red" ) ] ] [ text err ]
|
||||
, navBar model.route
|
||||
, div [ class "container pb-4" ] [ currentView model ]
|
||||
]
|
||||
|
||||
|
||||
renderCSS : String -> Html Msg
|
||||
renderCSS assetsUrl =
|
||||
div []
|
||||
[ cssNode (assetsUrl ++ "lib/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.min.css") BootstrapCSSLoaded
|
||||
, cssNode (assetsUrl ++ "lib/font-awesome-4.7.0/css/font-awesome.min.css") FontAwesomeCSSLoaded
|
||||
]
|
||||
|
||||
|
||||
cssNode : String -> (ApiData String -> Msg) -> Html Msg
|
||||
cssNode url msg =
|
||||
node "link"
|
||||
[ href url
|
||||
, rel "stylesheet"
|
||||
, on "load" (succeed (BootstrapCSSLoaded (Success url)))
|
||||
, on "error" (succeed (BootstrapCSSLoaded (Failure ("Failed to load Bootstrap CSS from: " ++ url))))
|
||||
]
|
||||
[]
|
||||
|
||||
|
||||
fontAwesome : Html msg
|
||||
fontAwesome =
|
||||
node "script"
|
||||
[ src "https://use.fontawesome.com/b7508bb100.js"
|
||||
, on "load" (succeed (msg (Success url)))
|
||||
, on "error" (succeed (msg (Failure ("Failed to load CSS from: " ++ url))))
|
||||
]
|
||||
[]
|
||||
|
||||
|
250
ui/bindata.go
250
ui/bindata.go
File diff suppressed because one or more lines are too long
6
ui/lib/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.min.css
vendored
Normal file
6
ui/lib/bootstrap-4.0.0-alpha.6-dist/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2337
ui/lib/font-awesome-4.7.0/css/font-awesome.css
vendored
Normal file
2337
ui/lib/font-awesome-4.7.0/css/font-awesome.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4
ui/lib/font-awesome-4.7.0/css/font-awesome.min.css
vendored
Normal file
4
ui/lib/font-awesome-4.7.0/css/font-awesome.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
ui/lib/font-awesome-4.7.0/fonts/FontAwesome.otf
Normal file
BIN
ui/lib/font-awesome-4.7.0/fonts/FontAwesome.otf
Normal file
Binary file not shown.
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.eot
Normal file
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.eot
Normal file
Binary file not shown.
2671
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.svg
Normal file
2671
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 434 KiB |
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf
Normal file
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf
Normal file
Binary file not shown.
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.woff
Normal file
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.woff
Normal file
Binary file not shown.
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2
Normal file
BIN
ui/lib/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2
Normal file
Binary file not shown.
@ -18,6 +18,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
|
||||
"path/filepath"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
@ -62,6 +63,13 @@ func Register(r *route.Router, reloadCh chan<- struct{}) {
|
||||
serveAsset(w, req, "ui/app/favicon.ico")
|
||||
}))
|
||||
|
||||
r.Get("/lib/*filepath", ihf("lib_files",
|
||||
func(w http.ResponseWriter, req *http.Request) {
|
||||
fp := route.Param(req.Context(), "filepath")
|
||||
serveAsset(w, req, filepath.Join("ui/lib", fp))
|
||||
},
|
||||
))
|
||||
|
||||
r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Write([]byte("Reloading configuration file..."))
|
||||
reloadCh <- struct{}{}
|
||||
|
Loading…
Reference in New Issue
Block a user