FicHub / fichub.net

web frontend for generating ebooks from fanfic
https://fichub.net
GNU Affero General Public License v3.0
48 stars 3 forks source link

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

Open necauqua opened 3 months ago

necauqua commented 3 months ago

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 ```js 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); ```