Allow 'bind' in config to specify bind address
Minimal changes, definitely WIP, to resolve: - how to support dualstack when not using localhost? - net/http package uses string, mentions IP address instead of bind, need info.
This commit is contained in:
parent
94badbc838
commit
543f6c9ae3
13
app.go
13
app.go
|
@ -404,6 +404,10 @@ func Serve() {
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
|
|
||||||
// Start web application server
|
// Start web application server
|
||||||
|
var bindAddress = app.cfg.Server.Bind
|
||||||
|
if bindAddress == "" {
|
||||||
|
bindAddress = "localhost"
|
||||||
|
}
|
||||||
if app.cfg.IsSecureStandalone() {
|
if app.cfg.IsSecureStandalone() {
|
||||||
log.Info("Serving redirects on http://localhost:80")
|
log.Info("Serving redirects on http://localhost:80")
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -413,13 +417,14 @@ func Serve() {
|
||||||
log.Error("Unable to start redirect server: %v", err)
|
log.Error("Unable to start redirect server: %v", err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Info("Serving on https://localhost:443")
|
log.Info("Serving on %s:443", bindAddress)
|
||||||
log.Info("---")
|
log.Info("---")
|
||||||
err = http.ListenAndServeTLS(":443", app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath, nil)
|
err = http.ListenAndServeTLS(
|
||||||
|
fmt.Sprintf("%s:443", bindAddress), app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath, nil)
|
||||||
} else {
|
} else {
|
||||||
log.Info("Serving on http://localhost:%d\n", app.cfg.Server.Port)
|
log.Info("Serving on http://%s:%d\n", bindAddress, app.cfg.Server.Port)
|
||||||
log.Info("---")
|
log.Info("---")
|
||||||
err = http.ListenAndServe(fmt.Sprintf(":%d", app.cfg.Server.Port), nil)
|
err = http.ListenAndServe(fmt.Sprintf("%s:%d", bindAddress, app.cfg.Server.Port), nil)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to start: %v", err)
|
log.Error("Unable to start: %v", err)
|
||||||
|
|
|
@ -12,6 +12,7 @@ type (
|
||||||
ServerCfg struct {
|
ServerCfg struct {
|
||||||
HiddenHost string `ini:"hidden_host"`
|
HiddenHost string `ini:"hidden_host"`
|
||||||
Port int `ini:"port"`
|
Port int `ini:"port"`
|
||||||
|
Bind string `ini:"bind"`
|
||||||
|
|
||||||
TLSCertPath string `ini:"tls_cert_path"`
|
TLSCertPath string `ini:"tls_cert_path"`
|
||||||
TLSKeyPath string `ini:"tls_key_path"`
|
TLSKeyPath string `ini:"tls_key_path"`
|
||||||
|
@ -60,6 +61,7 @@ func New() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
Server: ServerCfg{
|
Server: ServerCfg{
|
||||||
Port: 8080,
|
Port: 8080,
|
||||||
|
Bind: "localhost", /* IPV6 support when not using localhost? */
|
||||||
},
|
},
|
||||||
Database: DatabaseCfg{
|
Database: DatabaseCfg{
|
||||||
Type: "mysql",
|
Type: "mysql",
|
||||||
|
|
Loading…
Reference in New Issue