From d7b748476a98e6af9748aa59f17b2c4a80ff3b84 Mon Sep 17 00:00:00 2001 From: Uli Heller Date: Fri, 22 Jan 2021 14:57:30 +0100 Subject: [PATCH 1/4] Fixes #14422: Don't use sub-path twice for manifest --- modules/setting/setting.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index f69dd11cebcf3..c727e962caef2 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -104,6 +104,7 @@ var ( GracefulHammerTime time.Duration StartupTimeout time.Duration StaticURLPrefix string + StaticURLPrefixManifest string AbsoluteAssetURL string SSH = struct { @@ -606,6 +607,11 @@ func NewContext() { // Suburl should start with '/' and end without '/', such as '/{subpath}'. // This value is empty if site does not have sub-url. AppSubURL = strings.TrimSuffix(appURL.Path, "/") + // FIXME: Why does the content of 'StaticURLPrefixManifest' depend on the ordering of + // the next two lines? + // Manifest on top: "" + // Manifest below: "/gitea" + StaticURLPrefixManifest = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(""), "/") StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/") AppSubURLDepth = strings.Count(AppSubURL, "/") // Check if Domain differs from AppURL domain than update it to AppURL's domain @@ -614,7 +620,7 @@ func NewContext() { Domain = urlHostname } - AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefix) + AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefixManifest) manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL) ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes) From cc151bb3452d9ae822115b6e9401e86da376b602 Mon Sep 17 00:00:00 2001 From: Uli Heller Date: Fri, 22 Jan 2021 15:50:46 +0100 Subject: [PATCH 2/4] make fmt --- modules/setting/setting.go | 54 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index c727e962caef2..9faf1a9390ca4 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -79,33 +79,33 @@ var ( AppWorkPath string // Server settings - Protocol Scheme - Domain string - HTTPAddr string - HTTPPort string - LocalURL string - RedirectOtherPort bool - PortToRedirect string - OfflineMode bool - CertFile string - KeyFile string - StaticRootPath string - StaticCacheTime time.Duration - EnableGzip bool - LandingPageURL LandingPage - UnixSocketPermission uint32 - EnablePprof bool - PprofDataPath string - EnableLetsEncrypt bool - LetsEncryptTOS bool - LetsEncryptDirectory string - LetsEncryptEmail string - GracefulRestartable bool - GracefulHammerTime time.Duration - StartupTimeout time.Duration - StaticURLPrefix string - StaticURLPrefixManifest string - AbsoluteAssetURL string + Protocol Scheme + Domain string + HTTPAddr string + HTTPPort string + LocalURL string + RedirectOtherPort bool + PortToRedirect string + OfflineMode bool + CertFile string + KeyFile string + StaticRootPath string + StaticCacheTime time.Duration + EnableGzip bool + LandingPageURL LandingPage + UnixSocketPermission uint32 + EnablePprof bool + PprofDataPath string + EnableLetsEncrypt bool + LetsEncryptTOS bool + LetsEncryptDirectory string + LetsEncryptEmail string + GracefulRestartable bool + GracefulHammerTime time.Duration + StartupTimeout time.Duration + StaticURLPrefix string + StaticURLPrefixManifest string + AbsoluteAssetURL string SSH = struct { Disabled bool `ini:"DISABLE_SSH"` From 873012187f85eb63223cdd88fc804a837ae0ce6b Mon Sep 17 00:00:00 2001 From: Uli Heller Date: Thu, 28 Jan 2021 15:36:16 +0000 Subject: [PATCH 3/4] Eliminate extra variable --- modules/setting/setting.go | 60 +++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 9faf1a9390ca4..81db86d14cf27 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -79,33 +79,32 @@ var ( AppWorkPath string // Server settings - Protocol Scheme - Domain string - HTTPAddr string - HTTPPort string - LocalURL string - RedirectOtherPort bool - PortToRedirect string - OfflineMode bool - CertFile string - KeyFile string - StaticRootPath string - StaticCacheTime time.Duration - EnableGzip bool - LandingPageURL LandingPage - UnixSocketPermission uint32 - EnablePprof bool - PprofDataPath string - EnableLetsEncrypt bool - LetsEncryptTOS bool - LetsEncryptDirectory string - LetsEncryptEmail string - GracefulRestartable bool - GracefulHammerTime time.Duration - StartupTimeout time.Duration - StaticURLPrefix string - StaticURLPrefixManifest string - AbsoluteAssetURL string + Protocol Scheme + Domain string + HTTPAddr string + HTTPPort string + LocalURL string + RedirectOtherPort bool + PortToRedirect string + OfflineMode bool + CertFile string + KeyFile string + StaticRootPath string + StaticCacheTime time.Duration + EnableGzip bool + LandingPageURL LandingPage + UnixSocketPermission uint32 + EnablePprof bool + PprofDataPath string + EnableLetsEncrypt bool + LetsEncryptTOS bool + LetsEncryptDirectory string + LetsEncryptEmail string + GracefulRestartable bool + GracefulHammerTime time.Duration + StartupTimeout time.Duration + StaticURLPrefix string + AbsoluteAssetURL string SSH = struct { Disabled bool `ini:"DISABLE_SSH"` @@ -607,11 +606,6 @@ func NewContext() { // Suburl should start with '/' and end without '/', such as '/{subpath}'. // This value is empty if site does not have sub-url. AppSubURL = strings.TrimSuffix(appURL.Path, "/") - // FIXME: Why does the content of 'StaticURLPrefixManifest' depend on the ordering of - // the next two lines? - // Manifest on top: "" - // Manifest below: "/gitea" - StaticURLPrefixManifest = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(""), "/") StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/") AppSubURLDepth = strings.Count(AppSubURL, "/") // Check if Domain differs from AppURL domain than update it to AppURL's domain @@ -620,7 +614,7 @@ func NewContext() { Domain = urlHostname } - AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefixManifest) + AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(""), "/")) manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL) ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes) From 846bdfa28695afe7d6251a925fa4c35641bdd171 Mon Sep 17 00:00:00 2001 From: Uli Heller Date: Thu, 28 Jan 2021 15:45:00 +0000 Subject: [PATCH 4/4] Move new code upwards --- modules/setting/setting.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 81db86d14cf27..e07a3e043f4bd 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -606,6 +606,14 @@ func NewContext() { // Suburl should start with '/' and end without '/', such as '/{subpath}'. // This value is empty if site does not have sub-url. AppSubURL = strings.TrimSuffix(appURL.Path, "/") + // FIXME: The fix related to logo.png does not work when the ordering of the following lines + // is changed. + // OK: + // ... sec.Key("STATIC_URL_PREFIX").MustString("") is first, sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL) is 2nd + // KO: + // ... sec.Key("STATIC_URL_PREFIX").MustString("") is 2nd, sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL) is first + // Can someone who knows go explain this? + AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(""), "/")) StaticURLPrefix = strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(AppSubURL), "/") AppSubURLDepth = strings.Count(AppSubURL, "/") // Check if Domain differs from AppURL domain than update it to AppURL's domain @@ -614,8 +622,6 @@ func NewContext() { Domain = urlHostname } - AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, strings.TrimSuffix(sec.Key("STATIC_URL_PREFIX").MustString(""), "/")) - manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL) ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes)