Add rediretion when using https

This commit is contained in:
Marcos Lilljedahl
2017-09-08 16:14:01 -03:00
parent 3db24bf6a6
commit 19283a3c86
2 changed files with 13 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package handlers
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"os"
@@ -110,6 +111,16 @@ func Register() {
httpServer.TLSConfig = &tls.Config{
GetCertificate: certManager.GetCertificate,
}
go func() {
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
http.Redirect(rw, r, fmt.Sprintf("https://%s", r.Host), http.StatusMovedPermanently)
})
log.Println("Starting redirect server")
log.Fatal(http.ListenAndServe(":3001", nil))
log.Fatal(httpServer.ListenAndServe())
}()
log.Println("Listening on port " + config.PortNumber)
log.Fatal(httpServer.ListenAndServeTLS("", ""))
} else {