I currently have two middlewares: Auth and request logger. The desired behavior is to only run these middlewares for requests that are directed towards valid paths and all invalid paths should be redirected to another domain. Here's a simplified example of the code I have:
mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://example.com", http.StatusMovedPermanently)
}))
routes.AddRoutes(
mux,
config,
)
var handler http.Handler = mux
handler = middlewares.AuthMiddleware(handler, config)
handler = httplog.Logger(handler).
But the middlewares run and then it redirects. I don't want middlewares to be run for routes that are not defined. Any help will be appreciated.
mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://example.com", http.StatusMovedPermanently)
}))
routes.AddRoutes(
mux,
config,
)
var handler http.Handler = mux
handler = middlewares.AuthMiddleware(handler, config)
handler = httplog.Logger(handler).
But the middlewares run and then it redirects. I don't want middlewares to be run for routes that are not defined. Any help will be appreciated.