mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-10 15:43:09 -06:00
Add to muxes too
This commit is contained in:
parent
2f100c7993
commit
379b5058ab
|
|
@ -381,21 +381,6 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
internalRouter := externalRouter
|
internalRouter := externalRouter
|
||||||
|
|
||||||
notFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
_, _ = w.Write([]byte("endpoint not found"))
|
|
||||||
}
|
|
||||||
notAllowedHandler := func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
_, _ = w.Write([]byte(fmt.Sprintf("%s not allowed on this endpoint", r.Method)))
|
|
||||||
}
|
|
||||||
|
|
||||||
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notFoundHandler))
|
|
||||||
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
|
||||||
|
|
||||||
externalRouter.NotFoundHandler = notFoundCORSHandler
|
|
||||||
externalRouter.MethodNotAllowedHandler = notAllowedCORSHandler
|
|
||||||
|
|
||||||
externalServ := &http.Server{
|
externalServ := &http.Server{
|
||||||
Addr: string(externalAddr),
|
Addr: string(externalAddr),
|
||||||
WriteTimeout: HTTPServerTimeout,
|
WriteTimeout: HTTPServerTimeout,
|
||||||
|
|
@ -415,8 +400,6 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
// without enabling TLS.
|
// without enabling TLS.
|
||||||
internalH2S := &http2.Server{}
|
internalH2S := &http2.Server{}
|
||||||
internalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath()
|
internalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
internalRouter.NotFoundHandler = notFoundCORSHandler
|
|
||||||
internalRouter.MethodNotAllowedHandler = notAllowedCORSHandler
|
|
||||||
internalServ = &http.Server{
|
internalServ = &http.Server{
|
||||||
Addr: string(internalAddr),
|
Addr: string(internalAddr),
|
||||||
Handler: h2c.NewHandler(internalRouter, internalH2S),
|
Handler: h2c.NewHandler(internalRouter, internalH2S),
|
||||||
|
|
@ -426,6 +409,29 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
_, _ = w.Write([]byte("endpoint not found"))
|
||||||
|
}
|
||||||
|
notAllowedHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
_, _ = w.Write([]byte(fmt.Sprintf("%s not allowed on this endpoint", r.Method)))
|
||||||
|
}
|
||||||
|
|
||||||
|
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notFoundHandler))
|
||||||
|
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
||||||
|
|
||||||
|
for _, router := range []*mux.Router{
|
||||||
|
internalRouter, externalRouter,
|
||||||
|
b.DendriteAdminMux, b.SynapseAdminMux,
|
||||||
|
b.InternalAPIMux, b.PublicWellKnownAPIMux,
|
||||||
|
b.PublicClientAPIMux, b.PublicFederationAPIMux,
|
||||||
|
b.PublicKeyAPIMux, b.PublicMediaAPIMux,
|
||||||
|
} {
|
||||||
|
router.NotFoundHandler = notFoundCORSHandler
|
||||||
|
router.MethodNotAllowedHandler = notAllowedCORSHandler
|
||||||
|
}
|
||||||
|
|
||||||
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
||||||
if b.Cfg.Global.Metrics.Enabled {
|
if b.Cfg.Global.Metrics.Enabled {
|
||||||
internalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth))
|
internalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue