forked from planetdecred/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (38 loc) · 827 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
// To run: go run main.go
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"golang.org/x/crypto/acme/autocert"
)
func main() {
hostnames := []string{
"planetdecred.com",
}
tlsEnabled := 1
filesDir := "."
addr := ":443"
fs := http.FileServer(http.Dir(filesDir))
http.Handle("/", fs)
if tlsEnabled != 1 {
addr = ":8080"
}
s := &http.Server{
Addr: addr,
}
if addr == ":443" {
fmt.Printf("Serving TLS as %q..\n", hostnames)
m := autocert.Manager{
Prompt: autocert.AcceptTOS,
Cache: autocert.DirCache("/etc/secrets/acme/"),
HostPolicy: autocert.HostWhitelist(hostnames...),
}
s.TLSConfig = &tls.Config{GetCertificate: m.GetCertificate}
log.Fatal(s.ListenAndServeTLS("", ""))
} else {
fmt.Printf("Serving HTTP on %s..\n", addr)
log.Fatal(s.ListenAndServe())
}
}