Skip to content

Commit

Permalink
Add HTTPS_REDIRECT_PORT
Browse files Browse the repository at this point in the history
If set can override the port used for HTTP->HTTPS redirects
  • Loading branch information
JMalland authored and Sean-Der committed Apr 5, 2024
1 parent c1cb320 commit e502fcb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,21 @@ func main() {
}()
}

if os.Getenv("ENABLE_HTTP_REDIRECT") != "" {
httpsRedirectPort := "80"
if val := os.Getenv("HTTPS_REDIRECT_PORT"); val != "" {
httpsRedirectPort = val
}

if os.Getenv("HTTPS_REDIRECT_PORT") != "" || os.Getenv("ENABLE_HTTP_REDIRECT") != "" {
go func() {
redirectServer := &http.Server{
Addr: ":80",
Addr: ":" + httpsRedirectPort,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://"+r.Host+r.URL.String(), http.StatusMovedPermanently)
}),
}

log.Println("Running HTTP->HTTPS redirect Server at :80")
log.Println("Running HTTP->HTTPS redirect Server at :" + httpsRedirectPort)
log.Fatal(redirectServer.ListenAndServe())
}()

Expand Down

0 comments on commit e502fcb

Please sign in to comment.