diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-13 17:39:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 17:39:14 +0800 |
commit | 6037f183cfc09c4e82d6cab79a8efa1f187a5626 (patch) | |
tree | 41da2041a015a44670ab6b9e3d12806e767ebe8c /cmd/web.go | |
parent | 4b187f5167e43013b25ec89993d265cc85c44e12 (diff) | |
download | gitea-6037f183cfc09c4e82d6cab79a8efa1f187a5626.tar.gz gitea-6037f183cfc09c4e82d6cab79a8efa1f187a5626.zip |
fix run web with -p push failed (#3154) (#3179)
Diffstat (limited to 'cmd/web.go')
-rw-r--r-- | cmd/web.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cmd/web.go b/cmd/web.go index 811771aa5b..55546ea480 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -19,8 +19,10 @@ import ( "code.gitea.io/gitea/routers" "code.gitea.io/gitea/routers/routes" + "github.com/Unknwon/com" context2 "github.com/gorilla/context" "github.com/urfave/cli" + ini "gopkg.in/ini.v1" ) // CmdWeb represents the available web sub-command. @@ -69,6 +71,34 @@ func runWeb(ctx *cli.Context) error { if ctx.IsSet("port") { setting.AppURL = strings.Replace(setting.AppURL, setting.HTTPPort, ctx.String("port"), 1) setting.HTTPPort = ctx.String("port") + + switch setting.Protocol { + case setting.UnixSocket: + case setting.FCGI: + default: + // Save LOCAL_ROOT_URL if port changed + cfg := ini.Empty() + if com.IsFile(setting.CustomConf) { + // Keeps custom settings if there is already something. + if err := cfg.Append(setting.CustomConf); err != nil { + return fmt.Errorf("Failed to load custom conf '%s': %v", setting.CustomConf, err) + } + } + + defaultLocalURL := string(setting.Protocol) + "://" + if setting.HTTPAddr == "0.0.0.0" { + defaultLocalURL += "localhost" + } else { + defaultLocalURL += setting.HTTPAddr + } + defaultLocalURL += ":" + setting.HTTPPort + "/" + + cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL) + + if err := cfg.SaveTo(setting.CustomConf); err != nil { + return fmt.Errorf("Error saving generated JWT Secret to custom config: %v", err) + } + } } var listenAddr string |