use default 0.0.0.0 only when running in docker

This commit is contained in:
Gustavo Maronato 2023-08-18 19:11:20 -03:00
parent 1f078f2682
commit 8cdf445ece
Signed by: maronato
SSH Key Fingerprint: SHA256:2Gw7kwMz/As+2UkR1qQ/qYYhn+WNh3FGv6ozhoRrLcs
2 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
"os"
"strings"
"git.maronato.dev/maronato/goshort/internal/config"
@ -38,7 +39,11 @@ func NewSharedCmdOptions() []ff.Option {
func RegisterBaseFlags(fs *flag.FlagSet, cfg *config.Config) {
fs.BoolVar(&cfg.Debug, "debug", config.DefaultDebug, "enable debug mode")
fs.StringVar(&cfg.Host, "host", config.DefaultHost, "host to listen on")
var defaultHost = config.DefaultHost
if os.Getenv("ENV_DOCKER") == "true" {
defaultHost = "0.0.0.0"
}
fs.StringVar(&cfg.Host, "host", defaultHost, "host to listen on")
fs.StringVar(&cfg.Port, "port", config.DefaultPort, "port to listen on")
}

View File

@ -28,8 +28,8 @@ const (
DefaultDBURL = "goshort.db"
// DefaultPort is the default port to listen on.
DefaultPort = "8080"
// DefaultHost is the default host to listen on.
DefaultHost = "0.0.0.0"
// DefaultHost is the default host to listen on. This is set to 0.0.0.0 when running in Docker.
DefaultHost = "localhost"
// DefaultUIPort is the default port to listen on for the UI.
DefaultUIPort = "3000"
// DefaultDebug is the default debug mode.