Skip to content

Commit

Permalink
chore: readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadl0ck committed Mar 29, 2024
1 parent 8fb6331 commit 37871fe
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Simplecert has a default configuration available: *simplecert.Default*
You will need to update the *Domains*, *CacheDir* and *SSLEmail* and you are ready to go.

```go
// do the cert magic
// init simplecert
cfg := simplecert.Default
cfg.Domains = []string{"yourdomain.com", "www.yourdomain.com"}
cfg.CacheDir = "/etc/letsencrypt/live/yourdomain.com"
Expand All @@ -141,14 +141,20 @@ if err != nil {
log.Fatal("simplecert init failed: ", err)
}

// channel to handle errors
errChan := make(chan error)

// redirect HTTP to HTTPS
// CAUTION: This has to be done AFTER simplecert setup
// Otherwise Port 80 will be blocked and cert registration fails!
log.Println("starting HTTP Listener on Port 80")
go http.ListenAndServe(":80", http.HandlerFunc(redirect))
go func(){
errChan <- http.ListenAndServe(":80", http.HandlerFunc(simplecert.Redirect))
}()

// init strict tlsConfig with certReloader
// you could also use a default &tls.Config{}, but be warned this is highly insecure
// our foomo/tlsconfig provides a simple interface to configure the tls for different scenarios
tlsconf := tlsconfig.NewServerTLSConfig(tlsconfig.TLSModeServerStrict)

// now set GetCertificate to the reloaders GetCertificateFunc to enable hot reload
Expand All @@ -160,8 +166,13 @@ s := &http.Server{
TLSConfig: tlsconf,
}

// lets go
log.Fatal(s.ListenAndServeTLS("", ""))
// start serving in a new goroutine
go func() {
errChan <- s.ListenAndServeTLS("", "")
}()

// fatal on any errors
log.Fatal(<-errChan)
```

## Challenges
Expand Down

0 comments on commit 37871fe

Please sign in to comment.