How to configure JIRA API for allowed for cross-origin HTTP request

Clash Royale CLAN TAG#URR8PPP
How to configure JIRA API for allowed for cross-origin HTTP request
I want to integrate my app with JIRA, so when I send request to JIRA server its returns error call 'XMLHttpRequest cannot load https://*********/rest/api/2/project. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.'
This is my code
$http(
method: "GET",
url: "https://***********/rest/api/2/project",
headers:
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*******',
'Access-Control-Allow-Methods': 'GET, POST, DELETE, PUT, OPTIONS',
'Access-Control-Allow-Headers':'X-Requested-With, Content-Type, X-Codingpedia,Authorization'
,
dataType: "jsonp",
).then(function mySuccess(response)
$scope.myWelcome = response.data;
console.log(response.data);
, function myError(response)
$scope.myWelcome = response.statusText;
console.log(response.statusText);
);
};
Access-Control-Allow-Origin
Content-Type
Thanks for reply. I try to call from client side so I got this error.So then I call API through back end.Now issue was fixed.
– Lakmi
Aug 10 at 10:17
1 Answer
1
I don't know if you've got the answer, but still..
Just add this into your api server
app.use(function (req, res, next)
if (req.method === "OPTIONS")
// End CORS preflight request.
res.writeHead(204);
res.end();
else
req.fullurl = req.protocol + '://' + req.get('host') + req.originalUrl;
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Credentials', true);
next()
);
JIRA isn't written in Node.js with Express.
– Quentin
Aug 10 at 9:15
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Why are you adding
Access-Control-Allow-Originheaders to a request? Why are you adding aContent-Typeto a GET request?– Quentin
Aug 10 at 9:16