Commit fece9287 authored by Jeroen van Veen's avatar Jeroen van Veen Committed by Juliusz Chroboczek

Make https optional.

parent 2dcfe9ad
......@@ -24,6 +24,8 @@ func main() {
"web server root `directory`")
flag.StringVar(&webserver.Redirect, "redirect", "",
"redirect to canonical `host`")
flag.BoolVar(&webserver.Insecure, "insecure", false,
"act as an HTTP server rather than HTTPS")
flag.StringVar(&dataDir, "data", "./data/",
"data `directory`")
flag.StringVar(&group.Directory, "groups", "./groups/",
......
......@@ -33,6 +33,8 @@ var StaticRoot string
var Redirect string
var Insecure bool
func Serve(address string, dataDir string) error {
http.Handle("/", &fileHandler{http.Dir(StaticRoot)})
http.HandleFunc("/group/", groupHandler)
......@@ -68,10 +70,17 @@ func Serve(address string, dataDir string) error {
server.Store(s)
err := s.ListenAndServeTLS(
filepath.Join(dataDir, "cert.pem"),
filepath.Join(dataDir, "key.pem"),
)
var err error
if !Insecure {
err = s.ListenAndServeTLS(
filepath.Join(dataDir, "cert.pem"),
filepath.Join(dataDir, "key.pem"),
)
} else {
err = s.ListenAndServe()
}
if err == http.ErrServerClosed {
return nil
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment