diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-01-31 21:57:20 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-01-31 21:57:20 -0800 |
commit | b78172033fe9f03b5e1ffe4d235b9ab4fb23766d (patch) | |
tree | 7dc9a8e74c3cbc89356e6f9d46f7caa1774d0cd4 /config | |
parent | b0442e027771c2cf33b92557a7e73fa4f85849cf (diff) |
Show API URL endpoints in user interface
Diffstat (limited to 'config')
-rw-r--r-- | config/config.go | 6 | ||||
-rw-r--r-- | config/config_test.go | 39 |
2 files changed, 44 insertions, 1 deletions
diff --git a/config/config.go b/config/config.go index bf4f43d..7788a38 100644 --- a/config/config.go +++ b/config/config.go @@ -55,7 +55,11 @@ func (c *Config) HasDebugMode() bool { // BaseURL returns the application base URL. func (c *Config) BaseURL() string { - return c.get("BASE_URL", defaultBaseURL) + baseURL := c.get("BASE_URL", defaultBaseURL) + if baseURL[len(baseURL)-1:] == "/" { + baseURL = baseURL[:len(baseURL)-1] + } + return baseURL } // DatabaseURL returns the database URL. diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 0000000..4c01bc5 --- /dev/null +++ b/config/config_test.go @@ -0,0 +1,39 @@ +// Copyright 2017 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package config + +import ( + "os" + "testing" +) + +func TestGetCustomBaseURL(t *testing.T) { + os.Clearenv() + os.Setenv("BASE_URL", "http://example.org") + cfg := NewConfig() + + if cfg.BaseURL() != "http://example.org" { + t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL()) + } +} + +func TestGetCustomBaseURLWithTrailingSlash(t *testing.T) { + os.Clearenv() + os.Setenv("BASE_URL", "http://example.org/folder/") + cfg := NewConfig() + + if cfg.BaseURL() != "http://example.org/folder" { + t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL()) + } +} + +func TestGetDefaultBaseURL(t *testing.T) { + os.Clearenv() + cfg := NewConfig() + + if cfg.BaseURL() != "http://localhost" { + t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL()) + } +} |