Skip to content

fix: don't use cors proxy to read pastebin raw#220

Merged
taibeled merged 1 commit intotaibeled:masterfrom
RafDevX:no-corsanywhere-for-pastebin
Apr 9, 2026
Merged

fix: don't use cors proxy to read pastebin raw#220
taibeled merged 1 commit intotaibeled:masterfrom
RafDevX:no-corsanywhere-for-pastebin

Conversation

@RafDevX
Copy link
Copy Markdown
Contributor

@RafDevX RafDevX commented Apr 8, 2026

Pastebin's raw endpoint is not actually part of their API and so already supports CORS (it always sets the Access-Control-Allow-Origin header to *), so no proxy is required. This means significantly less probability of impact when the CORS proxy is down, as its usage is now restricted only to when posting to Pastebin (which should be relatively rare, compared to fetching information from a Paste).

Pastebin's raw endpoint is not actually part of their API and so already
supports CORS (it always sets the `Access-Control-Allow-Origin` header
to `*`), so no proxy is required. This means significantly less
probability of impact when the CORS proxy is down, as its usage is now
restricted only to when posting to Pastebin (which should be relatively
rare, compared to fetching information from a Paste).
@RafDevX
Copy link
Copy Markdown
Contributor Author

RafDevX commented Apr 8, 2026

Thank you for all your work - your project is essential to playing the home game, at least as far as we're concerned. Today unexpectedly we could not load our map bounds or custom station list because cors-anywhere was down, which means we had to play "blind" on where our bounds actually were, and I'd really like to avoid that ever happening again. As far as I can tell, this should fix the problem.

I understand cors-anywhere is a necessary evil sometimes, but it has extremely aggressive rate limiting and is often down in general (Internal Server Error), so I'd really like to limit its usage to when it's actually required to support base functionality.

@taibeled
Copy link
Copy Markdown
Owner

taibeled commented Apr 9, 2026

Thanks for researching this, I'll happily merge it!

@taibeled taibeled merged commit dc8e230 into taibeled:master Apr 9, 2026
@taibeled
Copy link
Copy Markdown
Owner

taibeled commented Apr 9, 2026

@all-contributors please add @RafDevX for code

@allcontributors
Copy link
Copy Markdown
Contributor

@taibeled

I've put up a pull request to add @RafDevX! 🎉

@taibeled
Copy link
Copy Markdown
Owner

taibeled commented Apr 9, 2026

I believe that this is actually a regression, as Pastebin links no longer appear to function due to the cors issue. As such, I'm going to revert this.

@RafDevX
Copy link
Copy Markdown
Contributor Author

RafDevX commented Apr 9, 2026

@taibeled Are you sure? The production version before the revert worked on my browser just fine, Pastebin links started working (didn't before because of cors anywhere). Is this a Chrome vs Firefox thing maybe? But I don't understand how, if the correct headers are sent

@RafDevX
Copy link
Copy Markdown
Contributor Author

RafDevX commented Apr 9, 2026

Oh, it's my bad, I understand now - I have Pastebin Pro and so my pastes automatically allow CORS for the raw endpoint. I only tested with my own pastes, not anyone else's. That's really unfortunate, don't know how to solve this then...

@taibeled
Copy link
Copy Markdown
Owner

taibeled commented Apr 9, 2026

Ah, that would explain it. I'm looking into alternative cors proxies now. Hopefully I can find one that is at least somewhat sufficient.

@RafDevX
Copy link
Copy Markdown
Contributor Author

RafDevX commented Apr 9, 2026

@taibeled Would you consider changing fetchFromPastebin to only use the CORS proxy if a normal request fails?

export async function fetchFromPastebin(pasteId: string): Promise<string> {
const response = await fetch(PASTEBIN_API_RAW_URL + pasteId);
if (!response.ok) {
throw new Error(
"Failed to fetch from Pastebin: " + response.statusText,
);
}
return response.text();
}

Doing something like

let response;
try {
    response = await fetch("https://pastebin.com/ ...");
} catch {
    response = await fetch("https://cors-anywhere.com/ ...");
}

This would completely solve my problem, but I understand if you're reluctant to make 2 requests for virtually every case (as long as the paste isn't from a Pro account). However, a CORS preflight request is pretty fast these days, and this is not a very common operation (happens once per page load, and only for people using pastebins).

Alternatively, would you be open to adding an option or a URL parameter to force this behavior? It would increase complexity, but honestly without a way to bypass the CORS proxy I think I'll have to fork this project and host it myself, as my last game was truly a terrible surprise to start playing and see that the proxy was down the whole day.

Thank you for considering, I really appreciate the work you're doing!

@taibeled
Copy link
Copy Markdown
Owner

taibeled commented Apr 9, 2026

A second fetch request should be fine. If you can make a pull request, that would be great. Due to cors anywhere already being so spotty, I doubt that another fetch would worsen the pastebin functionality any further.

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