1

I have this function that works perfectly in production however when running locally I get cors errors

export const listUsers = functions.https.onRequest(async (req, res) => {
    res.set("Access-Control-Allow-Origin", "*")
    const data = await getSomeUsers(10)
    res.json(data)
})

emulators starts fine:

enter image description here

cors issue:

enter image description here

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Nikos
  • 7,295
  • 7
  • 52
  • 88
  • 2
    Please don't show images of text. Edit the question and copy the text into the question itself so it's easier to read, copy, and search. – Doug Stevenson Jun 17 '20 at 21:53
  • I've been doing that for years, seems to me that the most important searchable stuff is already in there.. – Nikos Jun 19 '20 at 17:55
  • 3
    I'm asking as a favor for all the people with disabilities that find small graphical text to be difficult or impossible to read. Also, please read this: https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors – Doug Stevenson Jun 19 '20 at 19:31
  • They click on the image and it gets larger plus you have the colours. – Nikos Jun 20 '20 at 18:13
  • 11
    That's not the way disabilities work. It's most helpful to simply copy the text into the question. – Doug Stevenson Jun 20 '20 at 18:17
  • ok noted, thx.. – Nikos Jun 20 '20 at 18:18

1 Answers1

2

Check this:

Deadly CORS when http://localhost is the origin

Chrome does not support localhost for CORS requests (a bug opened in 2010, marked WontFix in 2014).

To get around this you can use a domain like lvh.me (which points at 127.0.0.1 just like localhost) or start chrome with the --disable-web-security flag (assuming you're just testing).

Ville Rinne
  • 801
  • 1
  • 7
  • 15
  • Can you tell me more about lvh.me ? – Nikos Jun 19 '20 at 17:56
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/26461727) – Bruno Jun 19 '20 at 21:57
  • @bruno, isn't the essential part included in the quote? – Ville Rinne Jun 20 '20 at 05:18
  • 1
    --disable-web-security works great thx for my issue – Nikos Jun 20 '20 at 18:15
  • 1
    Chrome does support CORS from localhost, this is extremely misleading. The bug was closed because it was not reproducible. – Pat Dec 15 '21 at 14:43