57805

Unable to test locally using firebase due to CORS restriction

<h3>Question</h3>

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

firebase serve

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)

Thanks.


<h3>Answer1:</h3>

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

来源:https://stackoverflow.com/questions/49856240/unable-to-test-locally-using-firebase-due-to-cors-restriction

Recommend

  • Regular expression syntax for hours
  • Accessing REMOTE_USER from PHP/CakePHP
  • The 'OraOLEDB.Oracle' provider is not registered on the local machine, when working with a
  • Unable to use Mapbox “Create an Upload” api to upload data file
  • How do I efficiently find the number of digits within a range in which the digits within the number
  • jQuery Waypoints - multiple divs with same CLASS
  • TeamCity: Scripting elements jsp:declaration, jsp:expression, jsp:scriptlet are disallowed here
  • Simulating a FULL OUTER JOIN in Access
  • Reveal Icon Button - Bootstrap 3
  • How to detect beginning of line, or: “The name 'getCharPositionInLine' does not exist in t
  • ODBC connection to an .accdb file
  • android 3G signal strength
  • how to synchronize web site content while loading page
  • UIImage to UIColor array of pixel colors
  • in Gwt, there are 2 different packages (or 2 options) for doing drag n Drop? Which one is better?
  • Enable CORS on Tomcat 8.0.30
  • Windows: How do I get the mode/access rights of an already opened file?
  • Adding Dynamic Row and Data on Checkbox Click
  • Using loops in Jasmine (with injected service)
  • Simultaneous animation when entering editing mode of UITableViewCell
  • Example of using Service Exists MSBuild task in Microsoft.Sdc.Tasks?
  • Create .java file and compile it to a .class file at runtime
  • Circular Left Rotation Algorithm in C#
  • Find all parks for a given zipcode with google maps
  • Silverlight Event Log in Isolated Storage
  • time column in sqlite using gorm
  • When to use the tag in the head and body section of a html page? [duplicate]
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • How to configure the APNS.Certificate in the arm template
  • Neo4j…how to get a visual representation of my data?
  • Geokit in Ruby on Rails, problem with acts_as_mappable
  • Support of :after in IE7
  • JavaScript Regex to Match Boundaries of Words with diacritics
  • Cloud Code: Creating a Parse.File from URL
  • Google App Engine Datastore: Dealing with eventual consistency
  • read part of h5 dataset python
  • How to check if object is null in Java?