Skip to content

Commit 929f1b0

Browse files
committed
Change redirector setting name, add a port to redirect setting
The Port to redirect in previous commit was hardcoded to 80, now it can be specified in the app.ini, defaulting to 80. The boolean option to turn redirection on has been changed to REDIRECT_OTHER_PORT to be logically consistent with the new port option.
1 parent d318310 commit 929f1b0

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

cmd/web.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ and it takes care of all the other things for you`,
5252
}
5353

5454
func runHTTPRedirector() {
55-
source := setting.HTTPAddr + ":80"
55+
source := fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.PortToRedirect)
5656
dest := strings.TrimSuffix(setting.AppURL, "/")
5757
log.Info("Redirecting: %s to %s", source, dest)
5858

@@ -67,7 +67,7 @@ func runHTTPRedirector() {
6767
var err = runHTTP(source, context2.ClearHandler(handler))
6868

6969
if err != nil {
70-
log.Fatal(4, "Failed to start port 80 redirector: %v", err)
70+
log.Fatal(4, "Failed to start port redirection: %v", err)
7171
}
7272
}
7373

@@ -144,7 +144,7 @@ func runWeb(ctx *cli.Context) error {
144144
case setting.HTTP:
145145
err = runHTTP(listenAddr, context2.ClearHandler(m))
146146
case setting.HTTPS:
147-
if setting.RedirectPort80 {
147+
if setting.RedirectOtherPort {
148148
go runHTTPRedirector()
149149
}
150150
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))

custom/conf/app.ini.sample

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
107107
; Listen address. Either a IPv4/IPv6 address or the path to a unix socket.
108108
HTTP_ADDR = 0.0.0.0
109109
HTTP_PORT = 3000
110-
; If true, and PROTOCOL is set to https, http requests on port 80 will be
111-
; redirected to ROOT_URL. Default is false.
112-
REDIRECT_PORT_80 = false
110+
; If REDIRECT_OTHER_PORT is true, and PROTOCOL is set to https an http server
111+
; will be started on PORT_TO_REDIRECT and redirect request to the main
112+
; ROOT_URL. Defaults are false for REDIRECT_OTHER_PORT and 80 for
113+
; PORT_TO_REDIRECT.
114+
REDIRECT_OTHER_PORT = false
115+
PORT_TO_REDIRECT = 80
113116
; Permission for unix socket
114117
UNIX_SOCKET_PERMISSION = 666
115118
; Local (DMZ) URL for Gitea workers (such as SSH update) accessing web service.

modules/setting/setting.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ var (
8989
HTTPAddr string
9090
HTTPPort string
9191
LocalURL string
92-
RedirectPort80 bool
92+
RedirectOtherPort bool
93+
PortToRedirect string
9394
OfflineMode bool
9495
DisableRouterLog bool
9596
CertFile string
@@ -733,7 +734,8 @@ func NewContext() {
733734
defaultLocalURL += ":" + HTTPPort + "/"
734735
}
735736
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
736-
RedirectPort80 = sec.Key("REDIRECT_PORT_80").MustBool(false)
737+
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
738+
PortToRedirect = sec.Key("PORT_TO_REDIRECT").MustString("80")
737739
OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
738740
DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()
739741
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(AppWorkPath)

0 commit comments

Comments
 (0)