I've encountered an issue with an XMLHttpRequest while working on a project. My front-end is responsible for loading a file and sending it to the back-end to create smart contracts. Everything works well when making a single request, but as soon as I attempt to load a file with more than 200 lines, using a custom function instead of the submit button in the form, I receive a CORS error:
Access to XMLHttpRequest at 'http://localhost/deploy_client' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The technologies I'm using are JavaScript and Node.JS with the Express library. The back-end is running on port 80, while the front-end is on port 8080.
This is the code snippet for the front-end:
Your rewritten front-end code goes here...
As for the back-end code:
Your rewritten back-end code goes here...
I'm quite new to dealing with CORS issues and still learning about server calls. Any guidance or assistance on this matter would be greatly appreciated. I've searched online for solutions but couldn't find one that fits my scenario. Thank you!
To address the CORS problem, the solution involves adding the CORS package and implementing the following:
The revised solution with the CORS package added should go here...
By including the provided solution, the CORS issue should be resolved successfully.