chore: add api specific 404 (#1272)

Prevents weird errors when routes are moved, like
https://github.com/coder/coder/issues/1205
This commit is contained in:
Colin Adler
2022-05-03 09:22:08 -05:00
committed by GitHub
parent ba80c799d7
commit e530ab2838

View File

@ -69,6 +69,7 @@ func New(options *Options) (http.Handler, func()) {
})
r := chi.NewRouter()
r.Use(
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -80,6 +81,12 @@ func New(options *Options) (http.Handler, func()) {
)
r.Route("/api/v2", func(r chi.Router) {
r.NotFound(func(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{
Message: "Route not found.",
})
})
r.Use(
// Specific routes can specify smaller limits.
httpmw.RateLimitPerMinute(options.APIRateLimit),