Skip to content

Commit

Permalink
Change redirector setting name, add a port to redirect setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MCF committed Dec 20, 2017
1 parent d318310 commit 929f1b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ and it takes care of all the other things for you`,
}

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

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

if err != nil {
log.Fatal(4, "Failed to start port 80 redirector: %v", err)
log.Fatal(4, "Failed to start port redirection: %v", err)
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func runWeb(ctx *cli.Context) error {
case setting.HTTP:
err = runHTTP(listenAddr, context2.ClearHandler(m))
case setting.HTTPS:
if setting.RedirectPort80 {
if setting.RedirectOtherPort {
go runHTTPRedirector()
}
err = runHTTPS(listenAddr, setting.CertFile, setting.KeyFile, context2.ClearHandler(m))
Expand Down
9 changes: 6 additions & 3 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
; Listen address. Either a IPv4/IPv6 address or the path to a unix socket.
HTTP_ADDR = 0.0.0.0
HTTP_PORT = 3000
; If true, and PROTOCOL is set to https, http requests on port 80 will be
; redirected to ROOT_URL. Default is false.
REDIRECT_PORT_80 = false
; If REDIRECT_OTHER_PORT is true, and PROTOCOL is set to https an http server
; will be started on PORT_TO_REDIRECT and redirect request to the main
; ROOT_URL. Defaults are false for REDIRECT_OTHER_PORT and 80 for
; PORT_TO_REDIRECT.
REDIRECT_OTHER_PORT = false
PORT_TO_REDIRECT = 80
; Permission for unix socket
UNIX_SOCKET_PERMISSION = 666
; Local (DMZ) URL for Gitea workers (such as SSH update) accessing web service.
Expand Down
6 changes: 4 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ var (
HTTPAddr string
HTTPPort string
LocalURL string
RedirectPort80 bool
RedirectOtherPort bool
PortToRedirect string
OfflineMode bool
DisableRouterLog bool
CertFile string
Expand Down Expand Up @@ -733,7 +734,8 @@ func NewContext() {
defaultLocalURL += ":" + HTTPPort + "/"
}
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
RedirectPort80 = sec.Key("REDIRECT_PORT_80").MustBool(false)
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
PortToRedirect = sec.Key("PORT_TO_REDIRECT").MustString("80")
OfflineMode = sec.Key("OFFLINE_MODE").MustBool()
DisableRouterLog = sec.Key("DISABLE_ROUTER_LOG").MustBool()
StaticRootPath = sec.Key("STATIC_ROOT_PATH").MustString(AppWorkPath)
Expand Down

0 comments on commit 929f1b0

Please sign in to comment.