custom favicon support

This commit is contained in:
mappu 2017-02-06 12:18:21 +13:00
parent 1189d6fe60
commit 99cf8ebe49
3 changed files with 17 additions and 7 deletions

View File

@ -10,6 +10,7 @@ type Config struct {
BindTo string `json:"bind_to"` BindTo string `json:"bind_to"`
Extern string `json:"extern"` Extern string `json:"extern"`
Title string `json:"title"` Title string `json:"title"`
CustomFavicon bool `json:"custom_favicon"`
ExternalWebroot bool `json:"external_webroot,omitempty"` ExternalWebroot bool `json:"external_webroot,omitempty"`
} }

12
main.go
View File

@ -181,6 +181,10 @@ func (this *App) SocketIOServer(so socketio.Socket) {
} }
func (this *App) customFaviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "favicon.ico")
}
func (this *App) ConfigRequestHandler(w http.ResponseWriter, r *http.Request) { func (this *App) ConfigRequestHandler(w http.ResponseWriter, r *http.Request) {
confStruct := struct { confStruct := struct {
@ -213,9 +217,9 @@ func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
knownContentTypes := map[string]string{ knownContentTypes := map[string]string{
".htm": "text/html", ".htm": "text/html",
".css": "text/css",
".js": "application/javascript",
".png": "image/png", ".png": "image/png",
".ico": "image/x-icon",
// No CSS/JS since they're embedded in the HTML
} }
foundMime := false foundMime := false
@ -251,6 +255,10 @@ func (this *App) RunServer() {
// Configuration handler // Configuration handler
http.HandleFunc("/conf", this.ConfigRequestHandler) http.HandleFunc("/conf", this.ConfigRequestHandler)
if this.cfg.Web.CustomFavicon {
http.HandleFunc("/favicon.ico", this.customFaviconHandler)
}
// Other files: asset handler // Other files: asset handler
if this.cfg.Web.ExternalWebroot { if this.cfg.Web.ExternalWebroot {
http.Handle("/", http.FileServer(http.Dir("client"))) http.Handle("/", http.FileServer(http.Dir("client")))

View File

@ -8,7 +8,8 @@
"port" : 8082, "port" : 8082,
"bind_to": "127.0.0.1", "bind_to": "127.0.0.1",
"extern" : "http://127.0.0.1:8082", "extern" : "http://127.0.0.1:8082",
"title" : "DCWebUI" "title" : "DCWebUI",
"custom_favicon": false
}, },
"hub": { "hub": {