From 6f6057fd56aa6d065ec59341b08cffc03619b21d Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Wed, 17 Apr 2024 19:53:22 +0200 Subject: config: override base_url in development --- internal/config/config.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index cab5f90..66e3d82 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -44,6 +44,15 @@ type Config struct { Menus map[string][]MenuItem } +func setDevelopmentOverrides(config *Config) error { + overrideURL, err := URL.Parse(config.BaseURL, "http://localhost:"+fmt.Sprint(config.Port)) + if err != nil { + return err + } + config.BaseURL.URL = overrideURL + return nil +} + func GetConfig() (*Config, error) { config := Config{} slog.Debug("reading config.toml") @@ -59,5 +68,11 @@ func GetConfig() (*Config, error) { return nil, errors.Wrap(err, "config error") } } + if os.Getenv("ENV") != "production" { + err = setDevelopmentOverrides(&config) + if err != nil { + return nil, errors.WithMessage(err, "could not override configuration") + } + } return &config, nil } -- cgit 1.4.1