In my production config of my live server I have this:
But that won’t work in my development config.
I tried to look it up what other parameters there are, but couldn’t find it.
I tried to remove the process in the development config, the site still works, but the fetch still won’t work.
gumroad.js:83 Error reading JSON: SyntaxError: Unexpected end of input (at gumroad.js:65:1)
at readJSON (gumroad.js:65:1)
This is the error message. It cannot read the data as it’s not been fetched correctly.
You can go to the URL in your browser and you’ll find the data. I get the data using a nodejs application and store it as a json file on my site.
The error isn’t there when it’s loaded on the live site and the data is getting read correctly.
If that’s the case, then your problem is that the browser is protecting you from bad actors by following the CORS policies set by the mindglowing.art server. You can’t fix that on the browser side, so you need to fix it on the server side. Do you control the server you’re fetching from, or have a good relationship with whoever owns it? If so, get it to return the right headers. If not, then you’re going to need to put a proxy of some sort between the user’s browser and that server, so that the browser makes the request of a server YOU control, that server makes a request to mindglowing.art (because servers don’t care about cors), then returns it to the user’s browser with the right headers set. (There are packages out there that do this - google it.)
Telling the browser to fetch in ‘no-cors’ mode is not usually the solution, because it means you don’t get the response body.
Okay, I guess I misunderstood your question then, sorry about that.
However, I own mindglowing.art and that site is running on my server (ghost docker). I do also run a local ghost development on that same server and I have proxied this to ghost-dev.mindglowing.art. So they are both on the same domain, on the same server (linux).
I’m executing the code in a js file in my theme asset folder and then run it through the browser. It is chrome’s console log indeed where I’m trying to read the JSON file.
Am I getting these errors because I’m on a subdomain or shouldn’t that matter?
So this also has nothing to do with running in development mode instead of production?
A subdomain is considered a different origin in this context. You’ll need to either change how you’re serving the JSON (how are you doing that btw?) or set up a proxy or other server to handle the request.
Okay I didn’t know that, thank you I fixed it now.
So basically I have a nodejs app running in a docker container which outputs a the api from gumroad being in json format.
I then proxy that nodejs container to /api/gumroad on my site.
So what I did now is proxy that nodejs container to location /api/gumroad on my ghost-dev subdomain and changed the fetch to /api/gumroad which is working.
I have also removed the no-cors and everything is working fine now.
Thanks for the help guys!