diff --git a/app/inithttp.go b/app/inithttp.go index 41e4fb8915..8f45326073 100644 --- a/app/inithttp.go +++ b/app/inithttp.go @@ -166,7 +166,7 @@ func (app *App) initHTTP(ctx context.Context) error { }) mux.Handle("/api/graphql", app.graphql2.Handler()) - mux.Handle("/api/graphql/explore", app.graphql2.PlayHandler()) + mux.HandleFunc("/api/graphql/explore", app.graphql2.PlayHandler) mux.HandleFunc("/api/v2/config", app.ConfigStore.ServeConfig) diff --git a/config/config.go b/config/config.go index 024721b5ff..997410719a 100644 --- a/config/config.go +++ b/config/config.go @@ -19,6 +19,7 @@ type Config struct { fallbackURL string General struct { + ApplicationName string `public:"true" info:"The name used in messaging and page titles. Defaults to \"GoAlert\"."` PublicURL string `public:"true" info:"Publicly routable URL for UI links and API calls."` GoogleAnalyticsID string `public:"true"` NotificationDisclaimer string `public:"true" info:"Disclaimer text for receiving pre-recorded notifications (appears on profile page)."` @@ -307,6 +308,14 @@ func (cfg Config) ValidReferer(reqURL, ref string) bool { return false } +// ApplicationName will return the General.ApplicationName +func (cfg Config) ApplicationName() string { + if cfg.General.ApplicationName == "" { + return "GoAlert" + } + return cfg.General.ApplicationName +} + // PublicURL will return the General.PublicURL or a fallback address (i.e. the app listening port). func (cfg Config) PublicURL() string { if cfg.General.PublicURL == "" { @@ -346,6 +355,10 @@ func (cfg Config) Validate() error { ) } + if cfg.General.ApplicationName != "" { + err = validate.Many(err, validate.ASCII("General.ApplicationName", cfg.General.ApplicationName, 0, 32)) + } + validateKey := func(fname, val string) error { return validate.ASCII(fname, val, 0, 128) } validatePath := func(fname, val string) error { if val == "" { diff --git a/config/store.go b/config/store.go index 772507870a..bd5a19db90 100644 --- a/config/store.go +++ b/config/store.go @@ -315,6 +315,7 @@ func (s *Store) updateConfigTx(ctx context.Context, tx *sql.Tx, fn func(Config) func (s *Store) Config() Config { s.mx.RLock() cfg := s.rawCfg + s.mx.RUnlock() return cfg } diff --git a/graphql2/graphqlapp/app.go b/graphql2/graphqlapp/app.go index 850a580b04..d15916f32f 100644 --- a/graphql2/graphqlapp/app.go +++ b/graphql2/graphqlapp/app.go @@ -85,31 +85,30 @@ type App struct { FormatDestFunc func(context.Context, notification.DestType, string) string } -func mustAuth(h http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - err := permission.LimitCheckAny(req.Context()) - if errutil.HTTPError(req.Context(), w, err) { - return - } +func (a *App) PlayHandler(w http.ResponseWriter, req *http.Request) { + var data struct { + ApplicationName string + Version string + PackageName string + } - h.ServeHTTP(w, req) - }) -} + ctx := req.Context() -func (a *App) PlayHandler() http.Handler { - var data struct { - Version string - PackageName string + err := permission.LimitCheckAny(ctx) + if errutil.HTTPError(ctx, w, err) { + return } + + cfg := config.FromContext(ctx) + + data.ApplicationName = cfg.ApplicationName() data.Version = playVersion data.PackageName = playPackageName - return mustAuth(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - err := playTmpl.Execute(w, data) - if err != nil { - log.Log(req.Context(), err) - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) - } - })) + + err = playTmpl.Execute(w, data) + if errutil.HTTPError(ctx, w, err) { + return + } } type fieldErr struct { diff --git a/graphql2/graphqlapp/playground.html b/graphql2/graphqlapp/playground.html index 1455918dbe..f5e50c42af 100644 --- a/graphql2/graphqlapp/playground.html +++ b/graphql2/graphqlapp/playground.html @@ -15,7 +15,7 @@ href="//cdn.jsdelivr.net/npm/{{ .PackageName }}@{{ .Version }}/build/favicon.png" /> -