-
Notifications
You must be signed in to change notification settings - Fork 15
/
ui.go
40 lines (35 loc) · 1.24 KB
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package http
import (
"net/http"
"strings"
"github.com/NYTimes/gziphandler"
"github.com/julienschmidt/httprouter"
)
func serveIndex() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Cache-Control", "max-age=180")
http.ServeFile(w, r, "static/index.html")
}
}
func serveFavicon() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Cache-Control", "max-age=180, immutable")
http.ServeFile(w, r, "static/favicon.ico")
}
}
func serveJavascript() httprouter.Handle {
fileServer := gziphandler.GzipHandler(http.FileServer(http.Dir("static/js")))
return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
req.URL.Path = p.ByName("filepath")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Cache-Control", "max-age=31536000, immutable")
if strings.HasSuffix(req.URL.Path, ".map") {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
} else {
w.Header().Set("Content-Type", "application/javascript; charset=UTF-8")
}
fileServer.ServeHTTP(w, req)
}
}