CORS error on same domain with content api?

Hi,

I have a page Tags - List of all tags on blog.kushalbhalaik.xyz where I want to list all my blog tags using code injection. I’m using fetch API to call “https://www.kushalbhalaik.xyz/ghost/api/v4/content/tags/?key=SOME_KEY” which works as a standalone call in my browser but not from within my website as I’m getting CORS error, it used to work a year ago, don’t know what changed with ghost v5.
Any Ideas


how to resolve this?

Could you say more about your hosting setup?

Its hosted by digitalpress.blog

Would you like to post the fetch request that’s not working? Are you missing mode: "cors" from the options you pass into fetch??

Since Ghost makes LOTS of requests to the server from the browser using fetch, this should absolutely work, so I’m guessing it’s something with your request.

it doesn’t work with mode: “cors”, but works with mode: “no-cors”, but that is causing other problems for me

no-cors will cause you not to get back a response body. That’s not going to be the solution.

Do you have the domain proxied or anything? If so, I’d try turning it all off.

Question: Does search work for you? That’s a call to the API from a front-end page. If it works, I’m sticking with my guess that there’s something wrong with the request you’re making, but if you don’t want to post it here, then I don’t see any way I can help you find the error if there is one.

You could also ask your host - perhaps they’re protecting you from cross site attacks in some overly enthusiastic way…?

1 Like

I’m getting data with the following code, but when I log it in one of the then blocks there’s nothing:

    fetch("https://kushalbhalaik.xyz/ghost/api/content/tags/?key=66378888e41585778ea70b1ee4&limit=100", {
        method: "GET",
        mode: "no-cors",
        headers: {
          "Content-Type": "application/json"
        }
      })
        .then((response) => response.json())
        .then((responseJson) => {
            console.log(responseJson)
       )}

The issue I’m facing now is becasue of pre-fetch flight request, as code execution doesn’t wait for the actual GET request. can I disable the pre-fetch flight request?

Fixed the issue, I was using the request without www which was causing the redirect. I mistakenly read Redirect as preflight. Thanks!!

1 Like