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

@ -6,10 +6,11 @@ type Config struct {
}
Web struct {
Port int `json:"port"`
BindTo string `json:"bind_to"`
Extern string `json:"extern"`
Title string `json:"title"`
Port int `json:"port"`
BindTo string `json:"bind_to"`
Extern string `json:"extern"`
Title string `json:"title"`
CustomFavicon bool `json:"custom_favicon"`
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) {
confStruct := struct {
@ -213,9 +217,9 @@ func (this *App) StaticRequestHandler(w http.ResponseWriter, r *http.Request) {
knownContentTypes := map[string]string{
".htm": "text/html",
".css": "text/css",
".js": "application/javascript",
".png": "image/png",
".ico": "image/x-icon",
// No CSS/JS since they're embedded in the HTML
}
foundMime := false
@ -251,6 +255,10 @@ func (this *App) RunServer() {
// Configuration handler
http.HandleFunc("/conf", this.ConfigRequestHandler)
if this.cfg.Web.CustomFavicon {
http.HandleFunc("/favicon.ico", this.customFaviconHandler)
}
// Other files: asset handler
if this.cfg.Web.ExternalWebroot {
http.Handle("/", http.FileServer(http.Dir("client")))

View File

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