Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heartbeat middleware is not invoked when added to a subrouter #821

Open
mo-rieger opened this issue May 3, 2023 · 1 comment
Open

Heartbeat middleware is not invoked when added to a subrouter #821

mo-rieger opened this issue May 3, 2023 · 1 comment

Comments

@mo-rieger
Copy link

Hi there,

The Heartbeat middleware is not invoked when attached to a sub router, whereas other middlewares are.

The expected behaviour would be that /connectivity/ping would return 200. Instead, a 404 is returned.

package main

import (
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
)

func main() {
	r := chi.NewRouter()

	r.Use(middleware.RequestID)
	r.Use(middleware.RealIP)
	r.Use(middleware.Recoverer)
	
	r.Mount("/connectivity", NewSubrouter())
	
	http.ListenAndServe(":3333", r)
}

func NewSubrouter() chi.Router {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Use(middleware.Heartbeat("/ping"))
	
	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("."))
	})
	
	return r
}

Best,
Moritz

@kubosuke
Copy link

kubosuke commented May 7, 2023

I created PR for this issue, please check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants