From fd579bde4495a50292f7cd414ebfb2eae7746701 Mon Sep 17 00:00:00 2001 From: Umputun Date: Sun, 4 Feb 2018 15:00:31 -0600 Subject: [PATCH] add /config --- app/rest/server.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/rest/server.go b/app/rest/server.go index 9be1a0ba..a1679a18 100644 --- a/app/rest/server.go +++ b/app/rest/server.go @@ -87,6 +87,7 @@ func (s *Server) Run(port int) { rapi.Get("/last/{max}", s.lastCommentsCtrl) rapi.Get("/count", s.countCtrl) rapi.Get("/list", s.listCtrl) + rapi.Get("/config", s.configCtrl) // protected routes, require auth rapi.With(auth.Auth(s.SessionStore, s.Admins, maybeWithDevMode(auth.Full))).Group(func(rauth chi.Router) { @@ -313,6 +314,29 @@ func (s *Server) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) { renderJSONFromBytes(w, r, data) } +// GET /config - returns configuration +func (s *Server) configCtrl(w http.ResponseWriter, r *http.Request) { + type config struct { + Version string + EditDuration time.Duration + Admins []string + Auth []string + } + + cnf := config{ + Version: s.Version, + EditDuration: s.DataService.EditDuration, + Admins: s.Admins, + } + authNames := []string{} + for _, ap := range s.AuthProviders { + authNames = append(authNames, ap.Name) + } + cnf.Auth = authNames + render.Status(r, http.StatusOK) + render.JSON(w, r, cnf) +} + // GET /user - returns user info func (s *Server) userInfoCtrl(w http.ResponseWriter, r *http.Request) { user, err := common.GetUserInfo(r)