Add TLS support
Fixes #20. Change-Id: I9c6b4ff3195f05e8a3c17d6704ee06b1f77db562
This commit is contained in:
parent
680eecb111
commit
cce3166bdd
@ -55,6 +55,9 @@ const usage = "vaind [init] <dbname>"
|
|||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
Port int
|
Port int
|
||||||
|
|
||||||
|
Cert string
|
||||||
|
Key string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -114,8 +117,17 @@ func main() {
|
|||||||
sm := http.NewServeMux()
|
sm := http.NewServeMux()
|
||||||
vain.NewServer(sm, db)
|
vain.NewServer(sm, db)
|
||||||
addr := fmt.Sprintf(":%d", c.Port)
|
addr := fmt.Sprintf(":%d", c.Port)
|
||||||
if err := http.ListenAndServe(addr, sm); err != nil {
|
|
||||||
log.Printf("problem with http server: %v", err)
|
if c.Cert == "" || c.Key == "" {
|
||||||
os.Exit(1)
|
log.Printf("INSECURE MODE")
|
||||||
|
if err := http.ListenAndServe(addr, sm); err != nil {
|
||||||
|
log.Printf("problem with http server: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := http.ListenAndServeTLS(addr, c.Cert, c.Key, sm); err != nil {
|
||||||
|
log.Printf("problem with http server: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,11 @@ func (s *Server) register(w http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(w, err.Message, err.Code)
|
http.Error(w, err.Message, err.Code)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("http://%s/api/v0/confirm/%+v", req.Host, tok)
|
proto := "https"
|
||||||
|
if req.TLS == nil {
|
||||||
|
proto = "http"
|
||||||
|
}
|
||||||
|
log.Printf("%s://%s/api/v0/confirm/%+v", proto, req.Host, tok)
|
||||||
fmt.Fprintf(w, "please check your email\n")
|
fmt.Fprintf(w, "please check your email\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user