1

Im using Node.js and TypeScript to try and use an api that returns a JSON.

When i click on the link in my browser it works perfectly fine, i can see the JSON file.

However, when i make a simple fetch request i get a CORS ERROR in my browser console. I tried to use { mode: 'no-cors' }, but then i dont have access to the body.

I checked my url and its fine.

can anyone tell me why is that?

my function:

async function fetchFeed() {
try {
    const response = await fetch(`${BASIC_URL}`, {
    })
    console.log(response);
    const posts = await response.json()
    console.log(posts);
    
} catch (err) {
    console.log('could note get posts' + err);
  }
}
Or Assayag
  • 5,662
  • 13
  • 57
  • 93
IdoBa
  • 63
  • 6
  • 1
    Does this answer your question? [Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i) – Matthieu Riegler Mar 23 '23 at 12:54
  • it answers why but still no solution. is there a solution other than contacting the server side ? – IdoBa Mar 23 '23 at 13:55
  • 1
    No, there is not. – Matthieu Riegler Mar 23 '23 at 13:59

0 Answers0