Repository navigation
fix(api): let the docs' Try it panel call the REST API - #242
Merged
Merged
Conversation
The "Try it" panel at medialit.cloud/docs/api calls api.medialit.cloud from the browser, but only /media/create and resumable uploads sent CORS headers, so every other endpoint failed its preflight. The REST API authenticates with an API key or bearer token, never a cookie, so allow any origin on /health, /media and /settings/media in one place instead of per route. The cookie-based dashboard API under /api stays same-origin. Co-Authored-By: Claude <noreply@anthropic.com>
Uploads keep accepting any origin, since browsers upload from customers' own sites with a signature. Every other REST endpoint needs an API key, which belongs on a server, so only https://medialit.cloud (the docs' "Try it" panel) may call those from a browser. Co-Authored-By: Claude <noreply@anthropic.com>
tus clients such as CourseLit read the uploaded media from the media response header, which browsers only expose across origins when the response lists it. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The API reference at https://medialit.cloud/docs/api has a "Try it" panel that calls
api.medialit.cloudfrom the browser. Only/media/createand resumable uploads sent CORS headers, so every other endpoint failed its preflight, and "Try it" didn't work for most of the API.One CORS rule in
app.tsnow covers/health,/mediaand/settings/media:/media/create,/media/create/resumable*https://medialit.cloudonlycors()calls on the upload routes are gone, because the app-level rule now covers them./api/...stays same-origin. The dashboard and themedialitSDK don't call the restricted endpoints from a browser: the dashboard goes through its own/api/apps/...routes, and the SDK runs on the server.rest-cors.test.tsruns against the real app and checks that:x-medialit-apikey;/api/appsdoesn't allow other origins.All 149 API tests, typecheck and lint pass.
Separately:
bun run swagger:generateonmainadds acontent-lengthheader parameter toswagger_output.json. That's existing drift that this change doesn't cause, so it's left out of this PR.