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

6
  • 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. Commented Jun 17, 2020 at 21:53
  • I've been doing that for years, seems to me that the most important searchable stuff is already in there.. Commented Jun 19, 2020 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: meta.stackoverflow.com/questions/303812/… Commented Jun 19, 2020 at 19:31
  • They click on the image and it gets larger plus you have the colours. Commented Jun 20, 2020 at 18:13
  • 11
    That's not the way disabilities work. It's most helpful to simply copy the text into the question. Commented Jun 20, 2020 at 18:17

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

5 Comments

Can you tell me more about lvh.me ?
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
@bruno, isn't the essential part included in the quote?
--disable-web-security works great thx for my issue
Chrome does support CORS from localhost, this is extremely misleading. The bug was closed because it was not reproducible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.