mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Separate muxes for public and internal APIs (#1056)
* Separate muxes for public and internal APIs * Update client-api-proxy and federation-api-proxy so they don't add /api to the path * Tidy up * Consistent HTTP setup * Set up prefixes properly
This commit is contained in:
parent
f223da2f35
commit
fe82e1f725
29 changed files with 131 additions and 119 deletions
|
@ -56,8 +56,9 @@ type BaseDendrite struct {
|
|||
componentName string
|
||||
tracerCloser io.Closer
|
||||
|
||||
// APIMux should be used to register new public matrix api endpoints
|
||||
APIMux *mux.Router
|
||||
// PublicAPIMux should be used to register new public matrix api endpoints
|
||||
PublicAPIMux *mux.Router
|
||||
InternalAPIMux *mux.Router
|
||||
EnableHTTPAPIs bool
|
||||
httpClient *http.Client
|
||||
Cfg *config.Dendrite
|
||||
|
@ -95,13 +96,15 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs
|
|||
logrus.WithError(err).Warnf("Failed to create cache")
|
||||
}
|
||||
|
||||
httpmux := mux.NewRouter()
|
||||
return &BaseDendrite{
|
||||
componentName: componentName,
|
||||
EnableHTTPAPIs: enableHTTPAPIs,
|
||||
tracerCloser: closer,
|
||||
Cfg: cfg,
|
||||
ImmutableCache: cache,
|
||||
APIMux: mux.NewRouter().UseEncodedPath(),
|
||||
PublicAPIMux: httpmux.PathPrefix(internal.HTTPPublicPathPrefix).Subrouter().UseEncodedPath(),
|
||||
InternalAPIMux: httpmux.PathPrefix(internal.HTTPInternalPathPrefix).Subrouter().UseEncodedPath(),
|
||||
httpClient: &http.Client{Timeout: HTTPClientTimeout},
|
||||
KafkaConsumer: kafkaConsumer,
|
||||
KafkaProducer: kafkaProducer,
|
||||
|
@ -221,7 +224,13 @@ func (b *BaseDendrite) SetupAndServeHTTP(bindaddr string, listenaddr string) {
|
|||
WriteTimeout: HTTPServerTimeout,
|
||||
}
|
||||
|
||||
internal.SetupHTTPAPI(http.DefaultServeMux, internal.WrapHandlerInCORS(b.APIMux), b.Cfg)
|
||||
internal.SetupHTTPAPI(
|
||||
http.DefaultServeMux,
|
||||
b.PublicAPIMux,
|
||||
b.InternalAPIMux,
|
||||
b.Cfg,
|
||||
b.EnableHTTPAPIs,
|
||||
)
|
||||
logrus.Infof("Starting %s server on %s", b.componentName, serv.Addr)
|
||||
|
||||
err := serv.ListenAndServe()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue