Add UseTLS config param for non-encrypted debugging

This commit is contained in:
Chandler Swift 2020-03-29 22:23:27 -05:00
parent c0a02d1194
commit 59c18fdaff

View file

@ -14,6 +14,7 @@ import (
) )
type config struct { type config struct {
UseTLS bool `json:"useTLS"`
Servers []server `json:"servers"` Servers []server `json:"servers"`
} }
@ -111,22 +112,29 @@ func main() {
t.Execute(w, data) t.Execute(w, data)
}) })
certManager := autocert.Manager{ if config.UseTLS {
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist("factorio.blackolivepineapple.pizza"), // TODO: add config certManager := autocert.Manager{
Cache: autocert.DirCache("certs"), Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist("factorio.blackolivepineapple.pizza"), // TODO: add config
Cache: autocert.DirCache("certs"),
}
srv := &http.Server{
Addr: ":https",
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
go http.ListenAndServe(":http", certManager.HTTPHandler(nil)) // Handler for LetsEncrypt
fmt.Println("Serving...")
srv.ListenAndServeTLS("", "") // Key/cert come from srv.TLSConfig
} else { // Debug
fmt.Println("Serving...")
http.ListenAndServe(":8080", nil) // TODO: pass as config value
} }
srv := &http.Server{
Addr: ":https",
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
go http.ListenAndServe(":http", certManager.HTTPHandler(nil)) // Handler for LetsEncrypt
fmt.Println("Serving...")
srv.ListenAndServeTLS("", "") // Key/cert come from srv.TLSConfig
} }