Solving “CORS Request did not Succeed” Error

I think this is a rare topic where StackOverflow actually gave me a completely ineffective answer. Generally there’s a step or two missing, and that’s okay. However, sometimes when CORS Requests fail it is not due to FireFox settings. I do not recommend messing with anything regarding website certificates unless you really know what you are doing. Honestly, the solution is far simpler than playing around with your settings anyway. What it boiled down to was effectively a single line of code that allows a connection from anywhere. To keep things simple when I mention “Express Server” think of it as a special container within code for information.

If you come across the error yourself what you may need to do is call “app.use” and within its parameters set “origin: *” within the file making sql queries. The asterisk is generally a special character that is a wildcard. So that line “origin: *” is just saying that requests can originate anywhere, including on the same server. You can of course make the settings more restrictive if you want by specifying domains. A case in which that may be desirable is one where you are getting too many outside requests. Etiquette regarding APIs is that you should gather as little information as possible, and make as few requests as possible. While my API is currently open to everyone it will likely be restricted once I actually deploy the new site to avoid those problems. The images below illustrates code that will help you fix header issues, and send information to other pages in JSON format.

The cors line that you may need, and some code to query a datbase in Node.JS.

If you make a purchase at Amazon using the link below I may receive commission.
Tech Best Sellers at Amazon

Leave a comment

Your email address will not be published. Required fields are marked *