Add Let's Encrypt integration

This commit is contained in:
Frédéric Guillot 2017-11-22 13:11:01 -08:00
parent 199b1fd6c3
commit 3b40ce4960
10 changed files with 32 additions and 21 deletions

View file

@ -20,6 +20,8 @@ const (
DefaultListenAddr = "127.0.0.1:8080"
DefaultCertFile = ""
DefaultKeyFile = ""
DefaultCertDomain = ""
DefaultCertCache = "/tmp/cert_cache"
)
// Config manages configuration parameters.

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.371264138 -0800 PST m=+0.036637447
// 2017-11-22 12:56:32.17637034 -0800 PST m=+0.027880962
package locale
@ -20,8 +20,8 @@ var Translations = map[string]string{
"%d erreurs"
],
"plural.categories.feed_count": [
"Il y %d abonnement.",
"Il y %d abonnements."
"Il y a %d abonnement.",
"Il y a %d abonnements."
],
"Username": "Nom d'utilisateur",
"Password": "Mot de passe",
@ -152,5 +152,5 @@ var Translations = map[string]string{
var TranslationsChecksums = map[string]string{
"en_US": "6fe95384260941e8a5a3c695a655a932e0a8a6a572c1e45cb2b1ae8baa01b897",
"fr_FR": "9a57dded2cf33b8c4d9a9d90dcbf18c96026ca396f409eb1a776ddc206fe0198",
"fr_FR": "c5ee8f6e8d573cd4ae0aa003b4a1e72ab400484e0f22b355702bb46409743881",
}

View file

@ -4,8 +4,8 @@
"%d erreurs"
],
"plural.categories.feed_count": [
"Il y %d abonnement.",
"Il y %d abonnements."
"Il y a %d abonnement.",
"Il y a %d abonnements."
],
"Username": "Nom d'utilisateur",
"Password": "Mot de passe",

View file

@ -12,6 +12,7 @@ import (
"github.com/gorilla/mux"
"github.com/miniflux/miniflux2/scheduler"
"golang.org/x/crypto/acme/autocert"
"github.com/miniflux/miniflux2/config"
"github.com/miniflux/miniflux2/reader/feed"
@ -26,6 +27,8 @@ func NewServer(cfg *config.Config, store *storage.Storage, pool *scheduler.Worke
func startServer(cfg *config.Config, handler *mux.Router) *http.Server {
certFile := cfg.Get("CERT_FILE", config.DefaultCertFile)
keyFile := cfg.Get("KEY_FILE", config.DefaultKeyFile)
certDomain := cfg.Get("CERT_DOMAIN", config.DefaultCertDomain)
certCache := cfg.Get("CERT_CACHE", config.DefaultCertCache)
server := &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
@ -34,23 +37,29 @@ func startServer(cfg *config.Config, handler *mux.Router) *http.Server {
Handler: handler,
}
if certFile != "" && keyFile != "" {
server.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
if certDomain != "" && certCache != "" {
server.Addr = ":https"
certManager := autocert.Manager{
Cache: autocert.DirCache(certCache),
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(certDomain),
}
go func() {
log.Printf(`Listening on "%s" by using auto-configured certificate for "%s"`, server.Addr, certDomain)
log.Fatalln(server.Serve(certManager.Listener()))
}()
} else if certFile != "" && keyFile != "" {
server.TLSConfig = &tls.Config{MinVersion: tls.VersionTLS12}
go func() {
log.Printf(`Listening on "%s" by using certificate "%s" and key "%s"`, server.Addr, certFile, keyFile)
if err := server.ListenAndServeTLS(certFile, keyFile); err != nil {
log.Fatalln(err)
}
log.Fatalln(server.ListenAndServeTLS(certFile, keyFile))
}()
} else {
go func() {
log.Printf(`Listening on "%s" without TLS`, server.Addr)
if err := server.ListenAndServe(); err != nil {
log.Fatalln(err)
}
log.Fatalln(server.ListenAndServe())
}()
}

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.342731949 -0800 PST m=+0.008105258
// 2017-11-22 12:56:32.154538505 -0800 PST m=+0.006049127
package static

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.344826414 -0800 PST m=+0.010199723
// 2017-11-22 12:56:32.155674865 -0800 PST m=+0.007185487
package static

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.347626921 -0800 PST m=+0.013000230
// 2017-11-22 12:56:32.159728625 -0800 PST m=+0.011239247
package static

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.368574596 -0800 PST m=+0.033947905
// 2017-11-22 12:56:32.174424983 -0800 PST m=+0.025935605
package template

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.350434639 -0800 PST m=+0.015807948
// 2017-11-22 12:56:32.16193023 -0800 PST m=+0.013440852
package template

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-11-21 22:32:06.338725044 -0800 PST m=+0.004098353
// 2017-11-22 12:56:32.152779508 -0800 PST m=+0.004290130
package sql