Skip to content

The API endpoint should return Access-Control-Allow-Origin: * for it to work from bookmarklets/usercripts #41

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

Open
necauqua opened this issue Jun 13, 2024 · 0 comments

Comments

@necauqua
Copy link

necauqua commented Jun 13, 2024

So I made a better bookmarklet so that there's less annoying clicks to download the thing (esp. on mobile)

Here's its source, very simple:

fetch('https://fichub.net/api/v0/epub?q=' + encodeURIComponent(location.href))
    .then(r => r.json())
    .then(j => location.href = 'https://fichub.net' + j.epub_url)

However, the /api/v0/epub endpoint does not return a proper CORS header, so the browser blocks the request originating from SB or what have you - it's a common issue with APIs like that.

The fix is to make the endpoint return Access-Control-Allow-Origin: * header.

My personal workaround for now is to have my very own server proxying this request (and adding the header) lul

if you read this you can use my thing until this is fixed ig, works great

THIS DOESN'T WORK!
I messed up my nginx config and sent some background chinese script spam noise hitting me their way, and they rightfully blocked my servers IP (how does one do that? it's just some cloudflare default maybe) sadly.


fetch('https://fichub.necauq.ua?q=' + encodeURIComponent(location.href))
    .then(r => r.json())
    .then(j => location.href = 'https://fichub.net' + j.epub_url)
//
// =>
//
// javascript:fetch("https://fichub.necauq.ua?q="+encodeURIComponent(location.href)).then(r=>r.json()).then(j=>location.href="https://fichub.net"+j.epub_url);
@necauqua necauqua changed the title API CORS issues The API endpoint should return Access-Control-Allow-Origin: * for it to work from bookmarklets/usercripts Jun 13, 2024
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

No branches or pull requests

1 participant