diff --git a/internal/config/config.go b/internal/config/config.go index f32c08c20..428c7866c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -437,12 +437,16 @@ func (c *Config) ApiUri() string { // CdnUrl returns the optional content delivery network URI without trailing slash. func (c *Config) CdnUrl(res string) string { + if c.options.CdnUrl == "" || c.options.CdnUrl == c.options.SiteUrl { + return res + } + return strings.TrimRight(c.options.CdnUrl, "/") + res } // CdnDomain returns the content delivery network domain name if specified. func (c *Config) CdnDomain() string { - if c.options.CdnUrl == "" { + if c.options.CdnUrl == "" || c.options.CdnUrl == c.options.SiteUrl { return "" } else if u, err := url.Parse(c.options.CdnUrl); err != nil { return "" @@ -453,7 +457,7 @@ func (c *Config) CdnDomain() string { // CdnVideo checks if videos should be streamed using the configured CDN. func (c *Config) CdnVideo() bool { - if c.options.CdnUrl == "" { + if c.options.CdnUrl == "" || c.options.CdnUrl == c.options.SiteUrl { return false } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index dd4eab8dc..e69be87ad 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -420,22 +420,31 @@ func TestConfig_ApiUri(t *testing.T) { func TestConfig_CdnUrl(t *testing.T) { c := NewConfig(CliTestContext()) + assert.Equal(t, "", c.options.SiteUrl) assert.Equal(t, "", c.CdnUrl("")) c.options.SiteUrl = "http://superhost:2342/" assert.Equal(t, "/", c.CdnUrl("/")) c.options.CdnUrl = "http://foo:2342/foo/" assert.Equal(t, "http://foo:2342/foo", c.CdnUrl("")) assert.Equal(t, "http://foo:2342/foo/", c.CdnUrl("/")) + c.options.SiteUrl = c.options.CdnUrl + assert.Equal(t, "/", c.CdnUrl("/")) + assert.Equal(t, "", c.CdnUrl("")) + c.options.SiteUrl = "" } func TestConfig_CdnDomain(t *testing.T) { c := NewConfig(CliTestContext()) + assert.Equal(t, "", c.options.SiteUrl) assert.Equal(t, "", c.CdnDomain()) c.options.CdnUrl = "http://superhost:2342/" assert.Equal(t, "superhost", c.CdnDomain()) c.options.CdnUrl = "https://foo.bar.com:2342/foo/" assert.Equal(t, "foo.bar.com", c.CdnDomain()) + c.options.SiteUrl = c.options.CdnUrl + assert.Equal(t, "", c.CdnDomain()) + c.options.SiteUrl = "" c.options.CdnUrl = "http:/invalid:2342/foo/" assert.Equal(t, "", c.CdnDomain()) c.options.CdnUrl = "" @@ -452,6 +461,10 @@ func TestConfig_CdnVideo(t *testing.T) { assert.False(t, c.CdnVideo()) c.options.CdnVideo = true assert.True(t, c.CdnVideo()) + c.options.SiteUrl = c.options.CdnUrl + assert.False(t, c.CdnVideo()) + c.options.SiteUrl = "" + assert.True(t, c.CdnVideo()) c.options.CdnVideo = false assert.False(t, c.CdnVideo()) c.options.CdnUrl = ""