dashboard: add the ability to use a remote dashboard, serve only local files: assets and eventualy public.json (to override given ones)
This commit is contained in:
parent
8c754fe265
commit
b205409679
3 changed files with 154 additions and 20 deletions
|
@ -14,6 +14,9 @@ import (
|
|||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var forwarder *string = nil
|
||||
var fwdPublicJson = false
|
||||
|
||||
func init() {
|
||||
api.Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
|
@ -36,80 +39,156 @@ func init() {
|
|||
})
|
||||
|
||||
api.Router().GET("/files/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(fic.FilesDir, strings.TrimPrefix(r.URL.Path, "/files")))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(fic.FilesDir, strings.TrimPrefix(r.URL.Path, "/files")))
|
||||
}
|
||||
})
|
||||
|
||||
api.Router().GET("/events.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "events.json"))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "events.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/my.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "public", "my.json"))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "public", "my.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/stats.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "public", "stats.json"))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "public", "stats.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/api/teams/:tid/stats.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.Redirect(w, r, "http://127.0.0.1:8081/api/teams/" + string(ps.ByName("tid")) + "/stats.json", 302)
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
fwd_request(w, r, "http://127.0.0.1:8081/")
|
||||
}
|
||||
})
|
||||
api.Router().GET("/settings.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("X-FIC-Time", fmt.Sprintf("%f", float64(time.Now().UnixNano()/1000)/1000000))
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(settings.SettingsDir, settings.SettingsFile))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
w.Header().Set("X-FIC-Time", fmt.Sprintf("%f", float64(time.Now().UnixNano()/1000)/1000000))
|
||||
http.ServeFile(w, r, path.Join(settings.SettingsDir, settings.SettingsFile))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/teams.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "teams.json"))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "teams.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/themes.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "themes.json"))
|
||||
if forwarder != nil {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(TeamsDir, "themes.json"))
|
||||
}
|
||||
})
|
||||
|
||||
api.Router().GET("/public.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public0.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public0.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public0.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public1.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public1.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public1.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public2.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public2.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public2.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public3.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public3.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public3.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public4.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public4.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public4.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public5.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public5.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public5.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public6.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public6.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public6.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public7.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public7.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public7.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public8.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public8.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public8.json"))
|
||||
}
|
||||
})
|
||||
api.Router().GET("/public9.json", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public9.json"))
|
||||
if forwarder != nil && fwdPublicJson {
|
||||
fwd_request(w, r, *forwarder)
|
||||
} else {
|
||||
http.ServeFile(w, r, path.Join(DashboardDir, "public9.json"))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Reference in a new issue