fix(nginx): add redirect for /api/v2/ trailing slash#2224
Conversation
|
Preview for this PR was built for commit |
|
The preview link is unfortunately not usable to test this, it has its own nginx IIRC. Server redirects are not working in the previews, even the old ones that work fine in production. |
barjin
left a comment
There was a problem hiding this comment.
This only fixes the one /api/v2/ URL.
Note that every other trailing-slash URL served by Docusaurus has the same issue (https://docs.apify.com/academy/, https://docs.apify.com/academy/puppeteer-playwright/ etc.)
I see little sense in adding only this if we don't fix all the other ones.
d6094b4 to
dd0a048
Compare
|
Let's hope we won't have to revert this, it feels a bit scary :] |
|
Preview for this PR was built for commit |
|
Hmm, this is in direct conflict with #2213, will just add a new rule behind those. |
Adds a general rewrite rule to remove trailing slashes from all URLs (except root /). This fixes the 404 error when accessing URLs like /api/v2/ with a trailing slash. The regex `^(.+)/$` matches any path with a trailing slash and redirects to the same path without it. The existing specific rules for GH pages docs are kept intact to avoid conflicts with other PRs. Slack thread: https://apify.slack.com/archives/C0L33UM7Z/p1770281199186039 https://claude.ai/code/session_01GqcrG6JU9Y1YaSA5ns87Yz
dd0a048 to
a62ea26
Compare
|
Preview for this PR was built for commit |
barjin
left a comment
There was a problem hiding this comment.
That's more like it, let's go! 😄
| rewrite ^/api/client/js/$ /api/client/js redirect; | ||
| rewrite ^/api/client/python/$ /api/client/python redirect; | ||
| rewrite ^/sdk/js/$ /sdk/js redirect; | ||
| rewrite ^/sdk/python/$ /sdk/python redirect; | ||
| rewrite ^/cli/$ /cli redirect; | ||
|
|
||
| # remove trailing slashes from all other URLs (except root /) | ||
| rewrite ^(.+)/$ $1 redirect; |
There was a problem hiding this comment.
I have a feeling that the rules above are still included in the new regex (and therefore unnecessary), but this shouldn't hurt anything anyway 👍
There was a problem hiding this comment.
The rules above are exactly what I meant by a conflict with another PR #2213
There are likely more places we can drop, let's clean it up later once the landing page PRs are merged.
When accessing /api/v2/ with a trailing slash, the page returned a 404 error. This adds a redirect to remove the trailing slash, matching the behavior of other similar paths like /sdk/js/, /cli/, etc.
Slack thread: https://apify.slack.com/archives/C0L33UM7Z/p1770281199186039
https://claude.ai/code/session_01GqcrG6JU9Y1YaSA5ns87Yz
Note
Low Risk
Single redirect rule change in
nginx.conf; low blast radius and no auth/data-handling logic involved.Overview
Fixes a 404 when hitting the API reference index with a trailing slash by adding an Nginx rewrite that redirects
/api/v2/to/api/v2, aligning this path with existing trailing-slash normalization for other docs entrypoints.Written by Cursor Bugbot for commit d6094b4. Configure here.