Skip to content

Commit 00bfa1d

Browse files
authored
fix run web with -p push failed (#3154)
1 parent 0b77dbc commit 00bfa1d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cmd/web.go

+30
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import (
1919
"code.gitea.io/gitea/routers"
2020
"code.gitea.io/gitea/routers/routes"
2121

22+
"github.com/Unknwon/com"
2223
context2 "github.com/gorilla/context"
2324
"github.com/urfave/cli"
25+
ini "gopkg.in/ini.v1"
2426
)
2527

2628
// CmdWeb represents the available web sub-command.
@@ -69,6 +71,34 @@ func runWeb(ctx *cli.Context) error {
6971
if ctx.IsSet("port") {
7072
setting.AppURL = strings.Replace(setting.AppURL, setting.HTTPPort, ctx.String("port"), 1)
7173
setting.HTTPPort = ctx.String("port")
74+
75+
switch setting.Protocol {
76+
case setting.UnixSocket:
77+
case setting.FCGI:
78+
default:
79+
// Save LOCAL_ROOT_URL if port changed
80+
cfg := ini.Empty()
81+
if com.IsFile(setting.CustomConf) {
82+
// Keeps custom settings if there is already something.
83+
if err := cfg.Append(setting.CustomConf); err != nil {
84+
return fmt.Errorf("Failed to load custom conf '%s': %v", setting.CustomConf, err)
85+
}
86+
}
87+
88+
defaultLocalURL := string(setting.Protocol) + "://"
89+
if setting.HTTPAddr == "0.0.0.0" {
90+
defaultLocalURL += "localhost"
91+
} else {
92+
defaultLocalURL += setting.HTTPAddr
93+
}
94+
defaultLocalURL += ":" + setting.HTTPPort + "/"
95+
96+
cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL)
97+
98+
if err := cfg.SaveTo(setting.CustomConf); err != nil {
99+
return fmt.Errorf("Error saving generated JWT Secret to custom config: %v", err)
100+
}
101+
}
72102
}
73103

74104
var listenAddr string

0 commit comments

Comments
 (0)