I am trying to send a GET request to a API but when i add custom headers in the code somthing strange happens. Somewhere the request method changes to OPTIONS when it reaches th
You probably want to install the cors
npm package https://www.npmjs.com/package/cors on the server where you have your http://localhost:8080/api/app
Node app running.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests has details about what’s happening here: Your appID
and authorizationkey
request headers are triggering your browser to send a CORS preflight OPTIONS
request before sending the GET
.
To handle that OPTIONS
request, you can install the cors
npm package and follow the instructions at https://www.npmjs.com/package/cors#enabling-cors-pre-flight to configure it:
var express = require('express')
, cors = require('cors')
, app = express();
app.options('*', cors()); // include before other routes
app.listen(80, function(){
console.log('CORS-enabled web server listening on port 80');
});