Add Monolith config options for HTTP(s) Bind Addresses

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
This commit is contained in:
Timo Rothenpieler 2022-10-07 21:32:20 +02:00 committed by BtbN
parent 31f56ac3f4
commit 3bfd5f18ae
4 changed files with 43 additions and 4 deletions

View file

@ -33,8 +33,8 @@ import (
)
var (
httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server")
httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server")
httpBindAddr = flag.String("http-bind-address", "", "The HTTP listening port for the server")
httpsBindAddr = flag.String("https-bind-address", "", "The HTTPS listening port for the server")
apiBindAddr = flag.String("api-bind-address", "localhost:18008", "The HTTP listening port for the internal HTTP APIs (if -api is enabled)")
certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS")
keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS")
@ -44,8 +44,14 @@ var (
func main() {
cfg := setup.ParseFlags(true)
httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
httpAddr := cfg.Global.Monolith.HTTPBindAddr
httpsAddr := cfg.Global.Monolith.HTTPBindAddr
if *httpBindAddr != "" {
httpAddr = config.HTTPAddress("http://" + *httpBindAddr)
}
if *httpsBindAddr != "" {
httpsAddr = config.HTTPAddress("https://" + *httpsBindAddr)
}
httpAPIAddr := httpAddr
options := []basepkg.BaseDendriteOptions{}
if *enableHTTPAPIs {

View file

@ -9,6 +9,12 @@ version: 2
# Global Matrix configuration. This configuration applies to all components.
global:
# Monolith specific configuration
monolith:
# HTTP and HTTPS bind address
http_bind_address: http://:8008
https_bind_address: https://:8448
# The domain name of this homeserver.
server_name: localhost

View file

@ -12,6 +12,9 @@ import (
)
type Global struct {
// Monolith specific configuration options, like bind address.
Monolith Monolith `yaml:"monolith,omitempty"`
// Signing identity contains the server name, private key and key ID of
// the deployment.
gomatrixserverlib.SigningIdentity `yaml:",inline"`
@ -96,6 +99,7 @@ func (c *Global) Defaults(opts DefaultOpts) {
if opts.Monolithic {
c.DatabaseOptions.Defaults(90)
}
c.Monolith.Defaults(opts)
c.JetStream.Defaults(opts)
c.Metrics.Defaults(opts)
c.DNSCache.Defaults()
@ -113,6 +117,7 @@ func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) {
v.Verify(configErrs)
}
c.Monolith.Verify(configErrs, isMonolith)
c.JetStream.Verify(configErrs, isMonolith)
c.Metrics.Verify(configErrs, isMonolith)
c.Sentry.Verify(configErrs, isMonolith)

View file

@ -0,0 +1,22 @@
package config
type Monolith struct {
HTTPBindAddr HTTPAddress `yaml:"http_bind_address"`
HTTPSBindAddr HTTPAddress `yaml:"https_bind_address"`
}
func (c *Monolith) Defaults(opts DefaultOpts) {
if !opts.Monolithic {
return
}
c.HTTPBindAddr = "http://:8008"
c.HTTPSBindAddr = "https://:8448"
}
func (c *Monolith) Verify(configErrs *ConfigErrors, isMonolith bool) {
if !isMonolith {
return
}
checkURL(configErrs, "monolith.http_bind_address", string(c.HTTPBindAddr))
checkURL(configErrs, "monolith.https_bind_address", string(c.HTTPSBindAddr))
}