Skip to content

Commit 5167096

Browse files
committed
fix REST OpenAPI redirect to include mount path
PR #579 fixed a path-absolute redirect bug but introduced a new issue: the redirect target was missing the /rest mount path, producing https://transit.land/api/v2/openapi.json instead of https://transit.land/api/v2/rest/openapi.json. Root cause: chi v5 does not strip r.URL.Path — it only updates rctx.RoutePath internally. So r.URL.Path in the handler still contains the full path (/rest/), the same value the pagination code already relies on when constructing `meta["next"]` links. Fix: combine cfg.RestPrefix (for the absolute base) with r.URL.Path (for the mount path) to produce a correct absolute redirect URL.
1 parent acbd2cb commit 5167096

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

server/rest/rest.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ func NewServer(graphqlHandler http.Handler) (http.Handler, error) {
5454
// Redirect root to OpenAPI documentation
5555
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
5656
cfg := model.ForContext(r.Context())
57-
http.Redirect(w, r, cfg.RestPrefix+"/openapi.json", http.StatusMovedPermanently)
57+
// chi does not strip r.URL.Path; it contains the full path (e.g. /rest/)
58+
// Use it to build the absolute redirect URL, consistent with how pagination links work
59+
path := strings.TrimRight(r.URL.Path, "/")
60+
http.Redirect(w, r, cfg.RestPrefix+path+"/openapi.json", http.StatusMovedPermanently)
5861
})
5962

6063
// OpenAPI Schema endpoint

0 commit comments

Comments
 (0)