API redirecting to URL with a trailing slash if one is not included
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3
- Forks
- 4
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 114
Description
Expected Behavior
The API returns a response
Current Behavior
The API sends back a 301 permanent redirect to the URL with a trailing slash at the end, which given the example below would be https://mit-open-rc.odl.mit.edu/api/v0/users/me/?format=json
Steps to Reproduce
- Navigate to an API endpoint like https://mit-open-rc.odl.mit.edu/api/v0/users/me?format=json
Additional Details
This was discovered while testing https://github.com/mitodl/mit-open/pull/429/. The mit-open API implementation in OCW is entirely done from frontend Javascript, with fetch commands (at least for now). When performing a fetch using a site that has to be accessed with CORS, a redirect breaks the flow. Since 3xx responses are not part of the CORS spec, the response is returned sans CORS headers. Since the request is a CORS request to begin with and the Access-Control-Allow-Origin header is not returned by the server with the 301, the browser generates a CORS error and does not follow the redirect. In order for this strategy to work in OCW, the API URLs need to follow the exact schema the API needs, and / or the API needs to not redirect and enforce a trailing slash.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the API route handling for an endpoint such as /api/v0/users/me and review how requests without a trailing slash are handled. Reproduce the request with and without the slash, then verify that the chosen URL behavior avoids a redirect that prevents the CORS response from being used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100