mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-28 17:32:22 +03:00
Simplify RealIP middleware setup
This commit is contained in:
parent
b442736a0f
commit
34c29a156f
@ -157,6 +157,15 @@ func clientUniqueIDMiddleware(next http.Handler) http.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// realIPMiddleware wraps the middleware.RealIP middleware function, bypassing it if the
|
||||||
|
// ReverseProxyWhitelist configuration option is set.
|
||||||
|
func realIPMiddleware(h http.Handler) http.Handler {
|
||||||
|
if conf.Server.ReverseProxyWhitelist == "" {
|
||||||
|
return middleware.RealIP(h)
|
||||||
|
}
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
// serverAddressMiddleware is a middleware function that modifies the request object
|
// serverAddressMiddleware is a middleware function that modifies the request object
|
||||||
// to reflect the address of the server handling the request, as determined by the
|
// to reflect the address of the server handling the request, as determined by the
|
||||||
// presence of X-Forwarded-* headers or the scheme and host of the request URL.
|
// presence of X-Forwarded-* headers or the scheme and host of the request URL.
|
||||||
|
@ -164,18 +164,13 @@ func (s *Server) initRoutes() {
|
|||||||
secureMiddleware(),
|
secureMiddleware(),
|
||||||
corsHandler(),
|
corsHandler(),
|
||||||
middleware.RequestID,
|
middleware.RequestID,
|
||||||
}
|
realIPMiddleware,
|
||||||
if conf.Server.ReverseProxyWhitelist == "" {
|
|
||||||
middlewares = append(middlewares, middleware.RealIP)
|
|
||||||
}
|
|
||||||
|
|
||||||
middlewares = append(middlewares,
|
|
||||||
middleware.Recoverer,
|
middleware.Recoverer,
|
||||||
middleware.Heartbeat("/ping"),
|
middleware.Heartbeat("/ping"),
|
||||||
robotsTXT(ui.BuildAssets()),
|
robotsTXT(ui.BuildAssets()),
|
||||||
serverAddressMiddleware,
|
serverAddressMiddleware,
|
||||||
clientUniqueIDMiddleware,
|
clientUniqueIDMiddleware,
|
||||||
)
|
}
|
||||||
|
|
||||||
// Mount the Native API /events endpoint with all middlewares, except the compress and request logger,
|
// Mount the Native API /events endpoint with all middlewares, except the compress and request logger,
|
||||||
// adding the authentication middlewares
|
// adding the authentication middlewares
|
||||||
|
Loading…
x
Reference in New Issue
Block a user