mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Update monolith -api mode listeners
This commit is contained in:
parent
ee79d662e7
commit
f90da7ee3d
|
|
@ -29,11 +29,13 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/serverkeyapi"
|
"github.com/matrix-org/dendrite/serverkeyapi"
|
||||||
"github.com/matrix-org/dendrite/userapi"
|
"github.com/matrix-org/dendrite/userapi"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server")
|
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")
|
httpsBindAddr = flag.String("https-bind-address", ":8448", "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")
|
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")
|
keyFile = flag.String("tls-key", "", "The PEM private key to use for TLS")
|
||||||
enableHTTPAPIs = flag.Bool("api", false, "Use HTTP APIs instead of short-circuiting (warning: exposes API endpoints!)")
|
enableHTTPAPIs = flag.Bool("api", false, "Use HTTP APIs instead of short-circuiting (warning: exposes API endpoints!)")
|
||||||
|
|
@ -44,22 +46,24 @@ func main() {
|
||||||
cfg := setup.ParseFlags(true)
|
cfg := setup.ParseFlags(true)
|
||||||
httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
|
httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
|
||||||
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
|
httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
|
||||||
|
httpAPIAddr := config.HTTPAddress("https://" + *apiBindAddr)
|
||||||
|
|
||||||
if *enableHTTPAPIs {
|
if *enableHTTPAPIs {
|
||||||
|
logrus.Warnf("DANGER! The -api option is enabled, exposing internal APIs on %q!", *apiBindAddr)
|
||||||
// If the HTTP APIs are enabled then we need to update the Listen
|
// If the HTTP APIs are enabled then we need to update the Listen
|
||||||
// statements in the configuration so that we know where to find
|
// statements in the configuration so that we know where to find
|
||||||
// the API endpoints. They'll listen on the same port as the monolith
|
// the API endpoints. They'll listen on the same port as the monolith
|
||||||
// itself.
|
// itself.
|
||||||
cfg.AppServiceAPI.InternalAPI.Connect = httpAddr
|
cfg.AppServiceAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.ClientAPI.InternalAPI.Connect = httpAddr
|
cfg.ClientAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.EDUServer.InternalAPI.Connect = httpAddr
|
cfg.EDUServer.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.FederationAPI.InternalAPI.Connect = httpAddr
|
cfg.FederationAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.FederationSender.InternalAPI.Connect = httpAddr
|
cfg.FederationSender.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.KeyServer.InternalAPI.Connect = httpAddr
|
cfg.KeyServer.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.MediaAPI.InternalAPI.Connect = httpAddr
|
cfg.MediaAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.RoomServer.InternalAPI.Connect = httpAddr
|
cfg.RoomServer.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.ServerKeyAPI.InternalAPI.Connect = httpAddr
|
cfg.ServerKeyAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
cfg.SyncAPI.InternalAPI.Connect = httpAddr
|
cfg.SyncAPI.InternalAPI.Connect = httpAPIAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
base := setup.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs)
|
base := setup.NewBaseDendrite(cfg, "Monolith", *enableHTTPAPIs)
|
||||||
|
|
@ -148,8 +152,8 @@ func main() {
|
||||||
// Expose the matrix APIs directly rather than putting them under a /api path.
|
// Expose the matrix APIs directly rather than putting them under a /api path.
|
||||||
go func() {
|
go func() {
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
config.HTTPAddress(httpAddr), // internal API
|
httpAPIAddr, // internal API
|
||||||
config.HTTPAddress(httpAddr), // external API
|
httpAddr, // external API
|
||||||
nil, nil, // TLS settings
|
nil, nil, // TLS settings
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
|
|
@ -157,8 +161,8 @@ func main() {
|
||||||
if *certFile != "" && *keyFile != "" {
|
if *certFile != "" && *keyFile != "" {
|
||||||
go func() {
|
go func() {
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
config.HTTPAddress(httpsAddr), // internal API
|
setup.NoInternalListener, // internal API
|
||||||
config.HTTPAddress(httpsAddr), // external API
|
httpsAddr, // external API
|
||||||
certFile, keyFile, // TLS settings
|
certFile, keyFile, // TLS settings
|
||||||
)
|
)
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ type BaseDendrite struct {
|
||||||
const HTTPServerTimeout = time.Minute * 5
|
const HTTPServerTimeout = time.Minute * 5
|
||||||
const HTTPClientTimeout = time.Second * 30
|
const HTTPClientTimeout = time.Second * 30
|
||||||
|
|
||||||
const NoExternalListener = ""
|
const NoInternalListener = ""
|
||||||
|
|
||||||
// NewBaseDendrite creates a new instance to be used by a component.
|
// NewBaseDendrite creates a new instance to be used by a component.
|
||||||
// The componentName is used for logging purposes, and should be a friendly name
|
// The componentName is used for logging purposes, and should be a friendly name
|
||||||
|
|
@ -272,23 +272,22 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
internalAddr, _ := internalHTTPAddr.Address()
|
internalAddr, _ := internalHTTPAddr.Address()
|
||||||
externalAddr, _ := externalHTTPAddr.Address()
|
externalAddr, _ := externalHTTPAddr.Address()
|
||||||
|
|
||||||
internalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
externalRouter := internalRouter
|
internalRouter := externalRouter
|
||||||
|
|
||||||
internalServ := &http.Server{
|
externalServ := &http.Server{
|
||||||
Addr: string(internalAddr),
|
|
||||||
WriteTimeout: HTTPServerTimeout,
|
|
||||||
Handler: internalRouter,
|
|
||||||
}
|
|
||||||
externalServ := internalServ
|
|
||||||
|
|
||||||
if externalAddr != NoExternalListener && externalAddr != internalAddr {
|
|
||||||
externalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath()
|
|
||||||
externalServ = &http.Server{
|
|
||||||
Addr: string(externalAddr),
|
Addr: string(externalAddr),
|
||||||
WriteTimeout: HTTPServerTimeout,
|
WriteTimeout: HTTPServerTimeout,
|
||||||
Handler: externalRouter,
|
Handler: externalRouter,
|
||||||
}
|
}
|
||||||
|
internalServ := externalServ
|
||||||
|
|
||||||
|
if internalAddr != NoInternalListener && externalAddr != internalAddr {
|
||||||
|
internalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
|
internalServ = &http.Server{
|
||||||
|
Addr: string(internalAddr),
|
||||||
|
Handler: internalRouter,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
||||||
|
|
@ -315,7 +314,7 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
logrus.Infof("Stopped %s listener on %s", b.componentName, internalServ.Addr)
|
logrus.Infof("Stopped %s listener on %s", b.componentName, internalServ.Addr)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if externalAddr != NoExternalListener && internalAddr != externalAddr {
|
if externalAddr != NoInternalListener && internalAddr != externalAddr {
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Infof("Starting %s listener on %s", b.componentName, externalServ.Addr)
|
logrus.Infof("Starting %s listener on %s", b.componentName, externalServ.Addr)
|
||||||
if certFile != nil && keyFile != nil {
|
if certFile != nil && keyFile != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue