I am facing issue calling Remote API from localhost.
I am using nimble:restivus
package
As per documentation I am setting:
enableCors: true
in order to allow access from any origin. But no luck.
This is the error I am getting in browser console:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at http://192.168.18.20:9000/api/getUsers.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Here is my server side code:
myApi = new Restivus({
apiPath: 'api/',
enableCors: true,
useDefaultAuth: false,
prettyJson: true,
defaultOptionsEndpoint: {
action: function() {
this.response.writeHead(201, {
"Access-Control-Allow-Origin", "*",
"Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Z-Key, Authorization"
"Content-Type": "application/json",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS"
});
this.done();
return {
status: "success",
"data": {
"message": "We love OPTIONS"
}
};
}
}
});
Here is my client side code:
$.ajax
({
type: "POST",
url: "https://example.com/api/getUsers",
dataType: 'json',
headers: {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5