mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 23:43:27 +01:00
Stop using CDNs + Remove bootstrap.min.js because it wasn't necessary
+ Gzip http.FileServer
This commit is contained in:
parent
ed4ed520b7
commit
e31c017a00
46
gzip.go
Normal file
46
gzip.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"compress/gzip"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var gzPool = sync.Pool{
|
||||||
|
New: func() interface{} {
|
||||||
|
return gzip.NewWriter(ioutil.Discard)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
type gzipResponseWriter struct {
|
||||||
|
io.Writer
|
||||||
|
http.ResponseWriter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *gzipResponseWriter) WriteHeader(status int) {
|
||||||
|
w.Header().Del("Content-Length")
|
||||||
|
w.ResponseWriter.WriteHeader(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *gzipResponseWriter) Write(b []byte) (int, error) {
|
||||||
|
return w.Writer.Write(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GzipHandler(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(writer http.ResponseWriter, r *http.Request) {
|
||||||
|
// If the request doesn't specify that it supports gzip, then don't compress it
|
||||||
|
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
|
next.ServeHTTP(writer, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writer.Header().Set("Content-Encoding", "gzip")
|
||||||
|
gz := gzPool.Get().(*gzip.Writer)
|
||||||
|
defer gzPool.Put(gz)
|
||||||
|
gz.Reset(writer)
|
||||||
|
defer gz.Close()
|
||||||
|
next.ServeHTTP(&gzipResponseWriter{ResponseWriter: writer, Writer: gz}, r)
|
||||||
|
})
|
||||||
|
}
|
2
main.go
2
main.go
@ -25,7 +25,7 @@ func main() {
|
|||||||
cfg := loadConfiguration()
|
cfg := loadConfiguration()
|
||||||
http.HandleFunc("/api/v1/results", serviceResultsHandler)
|
http.HandleFunc("/api/v1/results", serviceResultsHandler)
|
||||||
http.HandleFunc("/health", healthHandler)
|
http.HandleFunc("/health", healthHandler)
|
||||||
http.Handle("/", http.FileServer(http.Dir("./static")))
|
http.Handle("/", GzipHandler(http.FileServer(http.Dir("./static"))))
|
||||||
if cfg.Metrics {
|
if cfg.Metrics {
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
}
|
}
|
||||||
|
6
static/bootstrap.min.css
vendored
Normal file
6
static/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Health Dashboard</title>
|
<title>Health Dashboard</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
<link rel="stylesheet" href="/bootstrap.min.css" />
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
background-color: #f7f9fb;
|
background-color: #f7f9fb;
|
||||||
@ -22,13 +22,6 @@
|
|||||||
border-color: #dee2e6;
|
border-color: #dee2e6;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
}
|
}
|
||||||
.status-ok {
|
|
||||||
display: inline-block;
|
|
||||||
width: 1%;
|
|
||||||
height: 20px;
|
|
||||||
margin-right: 4px;
|
|
||||||
background-color: #28a745;
|
|
||||||
}
|
|
||||||
.status {
|
.status {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 500ms ease-in-out;
|
transition: all 500ms ease-in-out;
|
||||||
@ -93,7 +86,7 @@
|
|||||||
<div class="title display-4">Health Status</div>
|
<div class="title display-4">Health Status</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4 text-right">
|
<div class="col-4 text-right">
|
||||||
<img src="logo.png" alt="GaTuS" style="position: relative; min-width: 50px; max-width: 200px; width: 20%;"/>
|
<img src="logo.png" alt="Gatus" style="position: relative; min-width: 50px; max-width: 200px; width: 20%;"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -113,8 +106,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
<script src="/jquery.min.js"></script>
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let serviceStatuses = {};
|
let serviceStatuses = {};
|
||||||
|
2
static/jquery.min.js
vendored
Normal file
2
static/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 59 KiB |
Loading…
Reference in New Issue
Block a user