Skip to content

Commit

Permalink
Stop using CDNs + Remove bootstrap.min.js because it wasn't necessary
Browse files Browse the repository at this point in the history
+ Gzip http.FileServer
  • Loading branch information
TwiN committed Sep 6, 2020
1 parent ed4ed52 commit e31c017
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
46 changes: 46 additions & 0 deletions gzip.go
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
cfg := loadConfiguration()
http.HandleFunc("/api/v1/results", serviceResultsHandler)
http.HandleFunc("/health", healthHandler)
http.Handle("/", http.FileServer(http.Dir("./static")))
http.Handle("/", GzipHandler(http.FileServer(http.Dir("./static"))))
if cfg.Metrics {
http.Handle("/metrics", promhttp.Handler())
}
Expand Down
6 changes: 6 additions & 0 deletions static/bootstrap.min.css

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Health Dashboard</title>
<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>
html, body {
background-color: #f7f9fb;
Expand All @@ -22,13 +22,6 @@
border-color: #dee2e6;
border-style: solid;
}
.status-ok {
display: inline-block;
width: 1%;
height: 20px;
margin-right: 4px;
background-color: #28a745;
}
.status {
cursor: pointer;
transition: all 500ms ease-in-out;
Expand Down Expand Up @@ -93,7 +86,7 @@
<div class="title display-4">Health Status</div>
</div>
<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>
Expand All @@ -113,8 +106,7 @@
</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/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 src="/jquery.min.js"></script>

<script>
let serviceStatuses = {};
Expand Down
2 changes: 2 additions & 0 deletions static/jquery.min.js

Large diffs are not rendered by default.

Binary file removed static/logo-candidate.png
Binary file not shown.

0 comments on commit e31c017

Please sign in to comment.