# ChatGPT gave me a fetch example that works locally but fails with a CORS error online

Source: https://coursesweb.net/forum/t/chatgpt-gave-me-a-fetch-example-that-works-locally-but-fails/
Site: CoursesWeb Forum, category AI Coding Assistants and MCP
Published: 2026-11-28. Updated: 2026-11-29. Replies: 2.

## Question by Zaid M., 2026-11-28

hi everyone, im making a little game site with a high score table. i asked chatgpt for the code to load the scores and it gave me this fetch:

```js
fetch("https://api.mygame.example.com/scores")
  .then((res) => res.json())
  .then((data) => console.log(data));
```

on my laptop it works fine (i run the page and the node server together on localhost:3000). but after i uploaded the page to my hosting it just breaks and the console says:

`Access to fetch at 'https://api.mygame.example.com/scores' from origin 'https://mygame.example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

i asked chatgpt again and it told me to add mode: "no-cors" to the fetch. the error goes away but then res.json() fails and i get nothing. i dont really get what CORS even is, only that it hates me. the server is a small Express app. what do i change?

## Reply 1 by Bertie H., 2026-11-29

Open the Network tab and look at the response headers of that request. If there is no Access-Control-Allow-Origin in the list, the server is the problem, not your fetch. Use the browser's own view before you ask a chatbot.

## Reply 2 by Jun P., 2026-11-29

There is an npm package called cors that does this for Express. `npm install cors`, then `app.use(cors())` before your routes. It works, but check the options, because with no arguments it allows every origin.

---
Cite as: CoursesWeb Forum, "ChatGPT gave me a fetch example that works locally but fails with a CORS error online", https://coursesweb.net/forum/t/chatgpt-gave-me-a-fetch-example-that-works-locally-but-fails/, accessed 2026-11-29.
