mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
add bindAddress configuration option (#320)
* add bindAddress configuration option * clarify that bindAddress can be a hostname
This commit is contained in:
@@ -53,6 +53,7 @@ type Config struct {
|
||||
Host string `yaml:"host"`
|
||||
AccountDomain string `yaml:"accountDomain"`
|
||||
Protocol string `yaml:"protocol"`
|
||||
BindAddress string `yaml:"bindAddress"`
|
||||
Port int `yaml:"port"`
|
||||
TrustedProxies []string `yaml:"trustedProxies"`
|
||||
DBConfig *DBConfig `yaml:"db"`
|
||||
@@ -159,6 +160,10 @@ func (c *Config) ParseCLIFlags(f KeyedFlags, version string) error {
|
||||
return errors.New("protocol was not set")
|
||||
}
|
||||
|
||||
if c.BindAddress == "" || f.IsSet(fn.BindAddress) {
|
||||
c.BindAddress = f.String(fn.BindAddress)
|
||||
}
|
||||
|
||||
if c.Port == 0 || f.IsSet(fn.Port) {
|
||||
c.Port = f.Int(fn.Port)
|
||||
}
|
||||
@@ -374,6 +379,7 @@ type Flags struct {
|
||||
Host string
|
||||
AccountDomain string
|
||||
Protocol string
|
||||
BindAddress string
|
||||
Port string
|
||||
TrustedProxies string
|
||||
|
||||
@@ -438,6 +444,7 @@ type Defaults struct {
|
||||
Host string
|
||||
AccountDomain string
|
||||
Protocol string
|
||||
BindAddress string
|
||||
Port int
|
||||
TrustedProxies []string
|
||||
SoftwareVersion string
|
||||
@@ -505,6 +512,7 @@ func GetFlagNames() Flags {
|
||||
Host: "host",
|
||||
AccountDomain: "account-domain",
|
||||
Protocol: "protocol",
|
||||
BindAddress: "bind-address",
|
||||
Port: "port",
|
||||
TrustedProxies: "trusted-proxies",
|
||||
|
||||
@@ -572,6 +580,7 @@ func GetEnvNames() Flags {
|
||||
Host: "GTS_HOST",
|
||||
AccountDomain: "GTS_ACCOUNT_DOMAIN",
|
||||
Protocol: "GTS_PROTOCOL",
|
||||
BindAddress: "GTS_BIND_ADDRESS",
|
||||
Port: "GTS_PORT",
|
||||
TrustedProxies: "GTS_TRUSTED_PROXIES",
|
||||
|
||||
|
@@ -11,6 +11,7 @@ func TestDefault() *Config {
|
||||
Host: defaults.Host,
|
||||
AccountDomain: defaults.AccountDomain,
|
||||
Protocol: defaults.Protocol,
|
||||
BindAddress: defaults.BindAddress,
|
||||
Port: defaults.Port,
|
||||
TrustedProxies: defaults.TrustedProxies,
|
||||
SoftwareVersion: defaults.SoftwareVersion,
|
||||
@@ -85,6 +86,7 @@ func Default() *Config {
|
||||
ApplicationName: defaults.ApplicationName,
|
||||
Host: defaults.Host,
|
||||
Protocol: defaults.Protocol,
|
||||
BindAddress: defaults.BindAddress,
|
||||
Port: defaults.Port,
|
||||
TrustedProxies: defaults.TrustedProxies,
|
||||
SoftwareVersion: defaults.SoftwareVersion,
|
||||
@@ -161,6 +163,7 @@ func GetDefaults() Defaults {
|
||||
Host: "",
|
||||
AccountDomain: "",
|
||||
Protocol: "https",
|
||||
BindAddress: "0.0.0.0",
|
||||
Port: 8080,
|
||||
TrustedProxies: []string{"127.0.0.1/32"}, // localhost
|
||||
|
||||
@@ -227,6 +230,7 @@ func GetTestDefaults() Defaults {
|
||||
Host: "localhost:8080",
|
||||
AccountDomain: "localhost:8080",
|
||||
Protocol: "http",
|
||||
BindAddress: "127.0.0.1",
|
||||
Port: 8080,
|
||||
TrustedProxies: []string{"127.0.0.1/32"},
|
||||
|
||||
|
@@ -72,7 +72,8 @@ func (r *router) Start() {
|
||||
if r.config.LetsEncryptConfig.Enabled {
|
||||
// serve the http handler on the selected letsencrypt port, for receiving letsencrypt requests and solving their devious riddles
|
||||
go func() {
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", r.config.LetsEncryptConfig.Port), r.certManager.HTTPHandler(http.HandlerFunc(httpsRedirect))); err != nil && err != http.ErrServerClosed {
|
||||
listen := fmt.Sprintf("%s:%d", r.config.BindAddress, r.config.LetsEncryptConfig.Port)
|
||||
if err := http.ListenAndServe(listen, r.certManager.HTTPHandler(http.HandlerFunc(httpsRedirect))); err != nil && err != http.ErrServerClosed {
|
||||
logrus.Fatalf("listen: %s", err)
|
||||
}
|
||||
}()
|
||||
@@ -138,8 +139,9 @@ func New(ctx context.Context, cfg *config.Config, db db.DB) (Router, error) {
|
||||
}
|
||||
|
||||
// create the http server here, passing the gin engine as handler
|
||||
listen := fmt.Sprintf("%s:%d", cfg.BindAddress, cfg.Port)
|
||||
s := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", cfg.Port),
|
||||
Addr: listen,
|
||||
Handler: engine,
|
||||
ReadTimeout: readTimeout,
|
||||
WriteTimeout: writeTimeout,
|
||||
|
Reference in New Issue
Block a user