-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API redirecting to URL with a trailing slash if one is not included #445
Comments
This is default behavior in django apps, which can be overrriden by including |
There are workarounds though if we want the trailing slash to be optional and have the url work with or without it. |
@mbertrand I see that, and ensuring that we use trailing slashes in the API URLs isn't a problem. When I was talking to @rhysyngsun about this though, he seemed to think that he had made the trailing slash optional already. Since it is not currently optional, should it be? If it was intended for it to function the way it does currently, that's fine. We can simply make sure we add trailing slashes to all the endpoints hit by |
@gumaerc Can you confirm is this still an issue? |
@sovsey I can confirm that the issue as described still exists, although the URLs above have changed. For example, if you hit https://api.mitopen-rc.odl.mit.edu/api/v0/users/me?format=json then you are redirected to https://api.mitopen-rc.odl.mit.edu/api/v0/users/me/?format=json. As to whether or not we actually need to address this, I'm not sure. The Further experimentation proved that we can export whole components from In theory, this issue can be closed as it does exist but is maybe not a problem. We should maybe wait until we do further work on integrating |
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
Additional Details
This was discovered while testing #429. The
mit-open
API implementation in OCW is entirely done from frontend Javascript, withfetch
commands (at least for now). When performing afetch
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 theAccess-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.The text was updated successfully, but these errors were encountered: