fix versions and turn off challenges port by default

This commit is contained in:
AJ ONeal 2020-11-20 13:57:40 -07:00
parent 6810c6f86d
commit b2d6bb7a08
2 changed files with 224 additions and 215 deletions

View File

@ -68,8 +68,8 @@ func main() {
"port to listen to (default localhost 3000)")
flag.StringVar(&lnAddr, "listen", "",
"IPv4 or IPv6 bind address + port (instead of --port)")
flag.StringVar(&challengesPort, "challenges-port", "80",
"port to use to respond to .well-known/acme-challenge tokens")
flag.StringVar(&challengesPort, "challenges-port", "",
"port to use to respond to .well-known/acme-challenge tokens (should be 80, if used)")
flag.StringVar(&dbURL, "db-url", "postgres://postgres:postgres@localhost:5432/postgres",
"database (postgres) connection url")
flag.StringVar(&secret, "secret", "",
@ -161,6 +161,7 @@ func main() {
mgmt.Init(store, provider)
if len(challengesPort) > 0 {
go func() {
fmt.Println("Listening for ACME challenges on :" + challengesPort)
r := chi.NewRouter()
@ -175,9 +176,18 @@ func main() {
os.Exit(1)
}
}()
}
fmt.Println("Listening on", lnAddr)
fmt.Fprintf(os.Stderr, "failed: %s", http.ListenAndServe(lnAddr, mgmt.RouteAll()))
r := chi.NewRouter()
r.Get("/version", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(ver() + "\n"))
})
r.Get("/api/version", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("TODO (json): " + ver() + "\n"))
})
mgmt.RouteAll(r)
fmt.Fprintf(os.Stderr, "failed: %s", http.ListenAndServe(lnAddr, r))
}
// newNameDotComDNSProvider is for the sake of demoing the tunnel

View File

@ -53,7 +53,7 @@ func getACMEChallenges(w http.ResponseWriter, r *http.Request) {
fsrv.ServeHTTP(w, r)
}
func RouteAll() chi.Router {
func RouteAll(r chi.Router) {
go func() {
for {
@ -74,7 +74,7 @@ func RouteAll() chi.Router {
}
}()
r := chi.NewRouter()
r.Route("/", func(r chi.Router) {
r.Use(middleware.Logger)
r.Use(middleware.Timeout(15 * time.Second))
r.Use(middleware.Recoverer)
@ -288,6 +288,5 @@ func RouteAll() chi.Router {
w.Write([]byte("Hello\n"))
})
})
return r
})
}