Skip to content
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

Add a custom CORS proxy for our clients #681

Merged
merged 1 commit into from
Jan 4, 2025
Merged

Add a custom CORS proxy for our clients #681

merged 1 commit into from
Jan 4, 2025

Conversation

davidmz
Copy link
Member

@davidmz davidmz commented Jan 4, 2025

Added

  • New API method GET /v2/cors-proxy?url=.... This method acts as a simple proxy for web clients that need to make requests to other origins (specifically, to oEmbed endpoints of media providers). The proxy is deliberately limited: the valid request origins and URL prefixes are defined in the server config (see the corsProxy config entry).


ctx.status = response.status;

for (const header of headersToPass) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the only place where headersToPass is used. Maybe it's better to inline it here? Will be more readable. [...].forEach((header) => {})

app/controllers/api/v2/CorsProxyController.ts Show resolved Hide resolved

if (typeof origin !== 'string') {
if (!allowedOrigins.includes('none')) {
throw new BadRequestException('Missing origin');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status 400 means that user has a chance to fix the situation. But it's not the case as origin is not manually chosen.

We need some other Status I believe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we have any better option. It is the client error (definitely not the server one), i.e. some of the 4xx codes. The 400 means 'some problem with the request that we can't specify more clearly by other 4xx codes'.

Of the other codes, only the 403 is more or less fits.

@davidmz davidmz force-pushed the cors-proxy branch 2 times, most recently from 28cf81d to f540bfa Compare January 4, 2025 18:19
indeyets
indeyets previously approved these changes Jan 4, 2025
@indeyets indeyets merged commit 9f11b9c into stable Jan 4, 2025
12 checks passed
@indeyets indeyets deleted the cors-proxy branch January 4, 2025 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants