My current usecase is simple, I just need to make a post request to a cloud function I have locally developed.
The catch is, when I fire
the hosting is deployed on localhost:5000
and cloud functions are deployed on localhost:5001
These both are from different origin as port is different. Thus, when the browser sends the initial preflight request, it fails with error message
Failed to load http://localhost:5001/projectname/region/sendEnquiry: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5000' is therefore not allowed access.
How can I set the headers for testing this locally?(Again here I am not a pro, I am guessing I will have same origin when I decide to deploy in production. If not, anyways I will still need the solution)
Note that the server and cloud functions are different services and will always be at different ports.
CORS is really triggered by cross-domain issues. If it's all local, there shouldn't really be a cross domain violation.
You didn't provide any info on your client, so we can't give you client specific workarounds. But there are several Chrome Extensions that allow you disable CORS checks for this kind of local testing. Search the Chrome Store and find one that suits your needs. https://chrome.google.com/webstore/search/cors?hl=en