Merge af11b39459
into 427f4980b9
This commit is contained in:
commit
0e0cc6d5da
24
app.go
24
app.go
|
@ -448,6 +448,8 @@ func Initialize(apper Apper, debug bool) (*App, error) {
|
||||||
return apper.App(), nil
|
return apper.App(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Listen = net.Listen
|
||||||
|
|
||||||
func Serve(app *App, r *mux.Router) {
|
func Serve(app *App, r *mux.Router) {
|
||||||
log.Info("Going to serve...")
|
log.Info("Going to serve...")
|
||||||
|
|
||||||
|
@ -505,17 +507,23 @@ requests. We recommend supplying a valid host name.`)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Info("Serving redirects on http://%s:80", bindAddress)
|
log.Info("Serving redirects on http://%s:80", bindAddress)
|
||||||
err = http.ListenAndServe(":80", m.HTTPHandler(nil))
|
listener, err := Listen("tcp", fmt.Sprintf("%s:80", bindAddress))
|
||||||
|
log.Error("Unable to listen on %s: %v", bindAddress, err)
|
||||||
|
err = http.Serve(listener, m.HTTPHandler(nil))
|
||||||
log.Error("Unable to start redirect server: %v", err)
|
log.Error("Unable to start redirect server: %v", err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Info("Serving on https://%s:443", bindAddress)
|
log.Info("Serving on https://%s:443", bindAddress)
|
||||||
log.Info("---")
|
log.Info("---")
|
||||||
err = s.ListenAndServeTLS("", "")
|
listener, err := Listen("tcp", fmt.Sprintf("%s:443", bindAddress))
|
||||||
|
log.Error("Unable to listen on %s: %v", bindAddress, err)
|
||||||
|
err = s.ServeTLS(listener, "", "")
|
||||||
|
log.Error("Unable to start https server: %v", err)
|
||||||
} else {
|
} else {
|
||||||
go func() {
|
go func() {
|
||||||
|
listener, err := Listen("tcp", fmt.Sprintf("%s:80", bindAddress))
|
||||||
|
log.Error("Unable to listen on %s: %v", bindAddress, err)
|
||||||
log.Info("Serving redirects on http://%s:80", bindAddress)
|
log.Info("Serving redirects on http://%s:80", bindAddress)
|
||||||
err = http.ListenAndServe(fmt.Sprintf("%s:80", bindAddress), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
err = http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, app.cfg.App.Host, http.StatusMovedPermanently)
|
http.Redirect(w, r, app.cfg.App.Host, http.StatusMovedPermanently)
|
||||||
}))
|
}))
|
||||||
log.Error("Unable to start redirect server: %v", err)
|
log.Error("Unable to start redirect server: %v", err)
|
||||||
|
@ -524,7 +532,10 @@ requests. We recommend supplying a valid host name.`)
|
||||||
log.Info("Serving on https://%s:443", bindAddress)
|
log.Info("Serving on https://%s:443", bindAddress)
|
||||||
log.Info("Using manual certificates")
|
log.Info("Using manual certificates")
|
||||||
log.Info("---")
|
log.Info("---")
|
||||||
err = http.ListenAndServeTLS(fmt.Sprintf("%s:443", bindAddress), app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath, r)
|
listener, err := Listen("tcp", fmt.Sprintf("%s:443", bindAddress))
|
||||||
|
log.Error("Unable to listen on %s: %v", bindAddress, err)
|
||||||
|
err = http.ServeTLS(listener, r, app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath)
|
||||||
|
log.Error("Unable to start https server: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
network := "tcp"
|
network := "tcp"
|
||||||
|
@ -546,7 +557,7 @@ requests. We recommend supplying a valid host name.`)
|
||||||
|
|
||||||
log.Info("Serving on %s://%s", protocol, bindAddress)
|
log.Info("Serving on %s://%s", protocol, bindAddress)
|
||||||
log.Info("---")
|
log.Info("---")
|
||||||
listener, err := net.Listen(network, bindAddress)
|
listener, err := Listen(network, bindAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not bind to address: %v", err)
|
log.Error("Could not bind to address: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -562,6 +573,7 @@ requests. We recommend supplying a valid host name.`)
|
||||||
|
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
err = http.Serve(listener, r)
|
err = http.Serve(listener, r)
|
||||||
|
log.Error("Unable to start http server: %v", err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to start: %v", err)
|
log.Error("Unable to start: %v", err)
|
||||||
|
|
|
@ -24,10 +24,13 @@ import (
|
||||||
|
|
||||||
func initGopher(apper Apper) {
|
func initGopher(apper Apper) {
|
||||||
handler := NewWFHandler(apper)
|
handler := NewWFHandler(apper)
|
||||||
|
|
||||||
gopher.HandleFunc("/", handler.Gopher(handleGopher))
|
gopher.HandleFunc("/", handler.Gopher(handleGopher))
|
||||||
log.Info("Serving on gopher://localhost:%d", apper.App().Config().Server.GopherPort)
|
log.Info("Serving on gopher://localhost:%d", apper.App().Config().Server.GopherPort)
|
||||||
gopher.ListenAndServe(fmt.Sprintf(":%d", apper.App().Config().Server.GopherPort), nil)
|
listener, err := Listen("tcp", fmt.Sprintf("%s:%d", apper.App().Config().Server.Bind, apper.App().Config().Server.GopherPort))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
gopher.Serve(listener, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
||||||
|
|
Loading…
Reference in New Issue