How to solve CORS issue in XMLHttpRequest by using Node.js?
Question
I am trying to do API request by using RESTful API, however, I got error message below from console.
XMLHttpRequest cannot load http://example.com/abcd. Response to preflight request doesn’t pass access control check: The ‘Access-Control-Allow-Origin’ header has a value ‘http://example.com' that is not equal to the supplied origin. Origin ‘http://example.com' is therefore not allowed access.
Answer
Add the following code into app.js
.
1 | app.use(function(req, res, next) { |
Reference
This is the end of post