Add let's encrypt support

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-08-30 10:31:26 -03:00
parent beec1628be
commit fc3dfa6844
2 changed files with 36 additions and 3 deletions

View File

@@ -1,11 +1,14 @@
package handlers
import (
"crypto/tls"
"log"
"net/http"
"os"
"time"
"golang.org/x/crypto/acme/autocert"
"github.com/googollee/go-socket.io"
gh "github.com/gorilla/handlers"
"github.com/gorilla/mux"
@@ -91,9 +94,23 @@ func Register() {
IdleTimeout: 30 * time.Second,
ReadHeaderTimeout: 5 * time.Second,
}
if config.UseLetsEncrypt {
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(config.LetsEncryptDomains...),
Cache: autocert.DirCache(config.LetsEncryptCertsDir),
}
httpServer.TLSConfig = &tls.Config{
GetCertificate: certManager.GetCertificate,
}
log.Println("Listening on port " + config.PortNumber)
log.Fatal(httpServer.ListenAndServeTLS("", ""))
} else {
log.Println("Listening on port " + config.PortNumber)
log.Fatal(httpServer.ListenAndServe())
}
log.Println("Listening on port " + config.PortNumber)
log.Fatal(httpServer.ListenAndServe())
}
func RegisterEvents(s *socketio.Server) {