Browse Source

Fix go get response if only app URL is custom in configuration (#2634)

* Fix go get response if only app URL is custom in configuration

* Rewrite to update Domain setting to match AppURL
Lauris BH 1 year ago
parent
commit
46cc45f049
2 changed files with 8 additions and 1 deletions
  1. 1 1
      modules/context/context.go
  2. 7 0
      modules/setting/setting.go

+ 1 - 1
modules/context/context.go

@@ -194,7 +194,7 @@ func Contexter() macaron.Handler {
194 194
 	</body>
195 195
 </html>
196 196
 `, map[string]string{
197
-				"GoGetImport":    path.Join(setting.Domain, setting.AppSubURL, ctx.Link),
197
+				"GoGetImport":    ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")),
198 198
 				"CloneLink":      models.ComposeHTTPSCloneURL(ownerName, repoName),
199 199
 				"GoDocDirectory": prefix + "{/dir}",
200 200
 				"GoDocFile":      prefix + "{/dir}/{file}#L{line}",

+ 7 - 0
modules/setting/setting.go

@@ -10,6 +10,7 @@ import (
10 10
 	"encoding/base64"
11 11
 	"fmt"
12 12
 	"io"
13
+	"net"
13 14
 	"net/mail"
14 15
 	"net/url"
15 16
 	"os"
@@ -664,6 +665,12 @@ func NewContext() {
664 665
 	// This value is empty if site does not have sub-url.
665 666
 	AppSubURL = strings.TrimSuffix(url.Path, "/")
666 667
 	AppSubURLDepth = strings.Count(AppSubURL, "/")
668
+	// Check if Domain differs from AppURL domain than update it to AppURL's domain
669
+	// TODO: Can be replaced with url.Hostname() when minimal GoLang version is 1.8
670
+	urlHostname := strings.SplitN(url.Host, ":", 2)[0]
671
+	if urlHostname != Domain && net.ParseIP(urlHostname) == nil {
672
+		Domain = urlHostname
673
+	}
667 674
 
668 675
 	var defaultLocalURL string
669 676
 	switch Protocol {