@@ -19,8 +19,10 @@ import (
19
19
"code.gitea.io/gitea/routers"
20
20
"code.gitea.io/gitea/routers/routes"
21
21
22
+ "github.com/Unknwon/com"
22
23
context2 "github.com/gorilla/context"
23
24
"github.com/urfave/cli"
25
+ ini "gopkg.in/ini.v1"
24
26
)
25
27
26
28
// CmdWeb represents the available web sub-command.
@@ -69,6 +71,34 @@ func runWeb(ctx *cli.Context) error {
69
71
if ctx .IsSet ("port" ) {
70
72
setting .AppURL = strings .Replace (setting .AppURL , setting .HTTPPort , ctx .String ("port" ), 1 )
71
73
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
+ }
72
102
}
73
103
74
104
var listenAddr string
0 commit comments