You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, we have a router which uses the heartbeat middleware and no strongly defined routes. If I run this and call curl localhost:3000/ping, I get 404 page not found back.
If we then add an empty, unrelated handler to the router and call the same URL:
r.Get("/foo", func(
res http.ResponseWriter,
req*http.Request,
) {
res.WriteHeader(http.StatusOK)
})
I now get . back as expected instead.
I understand that this is an unusual scenario. Our particular use-case is that we have a set of services that use a combination of GRPC and HTTP. We want to be able to monitor all services in the same way, so a service that has only GRPC routes, still needs to have an HTTP endpoint that can be pinged. Our other services that are either HTTP-only, or a combination or HTTP/GRPC work fine, but GRPC-only ones currently don't.
The text was updated successfully, but these errors were encountered:
hi there :) we're aware of this quirk. the best solution is to add a stub handler on "/" in your router. Chi mux requires at least one route to always be set.
@pkieltyka Thanks for the quick response. I've added r.HandleFunc("/", r.NotFoundHandler()) and this works for now. Are there any plans to address this in the future or is this not possible? If not, feel free to close this. Thanks!
When using a Chi router with no routes, global middlewares are not called. For example:
Here, we have a router which uses the heartbeat middleware and no strongly defined routes. If I run this and call
curl localhost:3000/ping
, I get404 page not found
back.If we then add an empty, unrelated handler to the router and call the same URL:
I now get
.
back as expected instead.I understand that this is an unusual scenario. Our particular use-case is that we have a set of services that use a combination of GRPC and HTTP. We want to be able to monitor all services in the same way, so a service that has only GRPC routes, still needs to have an HTTP endpoint that can be pinged. Our other services that are either HTTP-only, or a combination or HTTP/GRPC work fine, but GRPC-only ones currently don't.
The text was updated successfully, but these errors were encountered: