Skip to content

Commit a2d7671

Browse files
committed
api: only redirect GET requests on unversioned paths
The wildcard /api/* redirect was registered with HandleFunc which matches all HTTP methods. This prevents chi from returning 405 on versioned routes when the method is not allowed, causing infinite redirect loops instead. Restrict the redirect to GET only. Fixes: a214945 ("api: redirect unversioned /api requests to latest version") Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent ff2994c commit a2d7671

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎pkg/api/api.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func NewRouter(cfg *config.Config, database *bun.DB, baseURL string, bus db.Even
224224

225225
latest := supportedVersions[len(supportedVersions)-1]
226226
latestPrefix := fmt.Sprintf("/api/%d.%d", latest.Major, latest.Minor)
227-
r.HandleFunc("/api/*", func(w http.ResponseWriter, r *http.Request) {
227+
r.Get("/api/*", func(w http.ResponseWriter, r *http.Request) {
228228
rest := strings.TrimPrefix(r.URL.Path, "/api")
229229
http.Redirect(w, r, latestPrefix+rest, http.StatusMovedPermanently)
230230
})

0 commit comments

Comments
 (0)