mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-10 23:53:09 -06:00
Tweak setup
This commit is contained in:
parent
6e9d22bfa2
commit
2f100c7993
|
|
@ -381,6 +381,21 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
|||
externalRouter := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||
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{
|
||||
Addr: string(externalAddr),
|
||||
WriteTimeout: HTTPServerTimeout,
|
||||
|
|
@ -400,6 +415,8 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
|||
// without enabling TLS.
|
||||
internalH2S := &http2.Server{}
|
||||
internalRouter = mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||
internalRouter.NotFoundHandler = notFoundCORSHandler
|
||||
internalRouter.MethodNotAllowedHandler = notAllowedCORSHandler
|
||||
internalServ = &http.Server{
|
||||
Addr: string(internalAddr),
|
||||
Handler: h2c.NewHandler(internalRouter, internalH2S),
|
||||
|
|
@ -451,24 +468,6 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
|||
externalRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(b.PublicMediaAPIMux)
|
||||
externalRouter.PathPrefix(httputil.PublicWellKnownPrefix).Handler(b.PublicWellKnownAPIMux)
|
||||
|
||||
notFoundHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("not found: %q", r.RequestURI)))
|
||||
}
|
||||
notAllowedHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("%s not allowed: %q", r.Method, r.RequestURI)))
|
||||
}
|
||||
|
||||
notFoundCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notFoundHandler))
|
||||
notAllowedCORSHandler := httputil.WrapHandlerInCORS(http.HandlerFunc(notAllowedHandler))
|
||||
|
||||
internalRouter.NotFoundHandler = notFoundCORSHandler
|
||||
internalRouter.MethodNotAllowedHandler = notAllowedCORSHandler
|
||||
|
||||
externalRouter.NotFoundHandler = notFoundCORSHandler
|
||||
externalRouter.MethodNotAllowedHandler = notAllowedCORSHandler
|
||||
|
||||
if internalAddr != NoListener && internalAddr != externalAddr {
|
||||
go func() {
|
||||
var internalShutdown atomic.Bool // RegisterOnShutdown can be called more than once
|
||||
|
|
|
|||
Loading…
Reference in a new issue