49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package main
|
|
|
|
import "net/http"
|
|
|
|
func serveWebUI(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
w.Header().Set("Pragma", "no-cache")
|
|
w.Header().Set("Expires", "0")
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.Header().Set("X-XSS-Protection", "1")
|
|
w.Header().Set("X-Frame-Options", "DENY")
|
|
|
|
http.ServeFileFS(w, r, content, "ui/index.html")
|
|
}
|
|
func serveStaticContent(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/static/style.css":
|
|
darkTheme := r.CookiesNamed("dark_theme")
|
|
if len(darkTheme) > 0 && darkTheme[0].Value == "true" {
|
|
http.ServeFileFS(w, r, content, "ui/static/dark.css")
|
|
} else {
|
|
http.ServeFileFS(w, r, content, "ui/static/light.css")
|
|
}
|
|
case "/favicon.ico":
|
|
http.ServeFileFS(w, r, content, "ui/static/favicon.ico")
|
|
case "/static/index.js":
|
|
http.ServeFileFS(w, r, content, "ui/static/index.js")
|
|
case "/static/test.js":
|
|
http.ServeFileFS(w, r, content, "ui/static/test.js")
|
|
case "/static/test.css":
|
|
http.ServeFileFS(w, r, content, "ui/static/test.css")
|
|
case "/static/test_tests.js":
|
|
http.ServeFileFS(w, r, content, "ui/static/test_tests.js")
|
|
default:
|
|
http.NotFound(w, r)
|
|
|
|
}
|
|
}
|
|
func serveTester(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFileFS(w, r, content, "ui/test.html")
|
|
}
|
|
|
|
func uiRoutes(mux *http.ServeMux) {
|
|
mux.HandleFunc("GET /{$}", serveWebUI)
|
|
mux.HandleFunc("GET /favicon.ico", serveStaticContent)
|
|
mux.HandleFunc("GET /static/", serveStaticContent)
|
|
mux.HandleFunc("GET /test.html", serveTester)
|
|
}
|