mitodl / mitodl/mit-learn

API redirecting to URL with a trailing slash if one is not included

Open
#445 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug product:mit-open
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
  1. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.