Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 'bind' in config to specify bind address #38

Merged
merged 3 commits into from Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions app.go
Expand Up @@ -404,6 +404,10 @@ func Serve() {
http.Handle("/", r)

// Start web application server
var bindAddress = app.cfg.Server.Bind
if bindAddress == "" {
bindAddress = "localhost"
}
if app.cfg.IsSecureStandalone() {
log.Info("Serving redirects on http://localhost:80")
mrvdb marked this conversation as resolved.
Show resolved Hide resolved
go func() {
Expand All @@ -413,13 +417,14 @@ func Serve() {
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("---")
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 {
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("---")
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 {
log.Error("Unable to start: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Expand Up @@ -12,6 +12,7 @@ type (
ServerCfg struct {
HiddenHost string `ini:"hidden_host"`
Port int `ini:"port"`
Bind string `ini:"bind"`

TLSCertPath string `ini:"tls_cert_path"`
TLSKeyPath string `ini:"tls_key_path"`
Expand Down Expand Up @@ -60,6 +61,7 @@ func New() *Config {
return &Config{
Server: ServerCfg{
Port: 8080,
Bind: "localhost", /* IPV6 support when not using localhost? */
},
Database: DatabaseCfg{
Type: "mysql",
Expand Down