CORS issue
See original GitHub issueHaving trouble with CORS.
Investigative information
Please provide the following:
- Timestamp: 2:14PM November 14th 2018
- Function App name: recommender-test-4
- Function name(s) (as appropriate): GetRecommendations
Repro steps
Provide the steps required to reproduce the problem:
- Deployed this app.
- Returns json as expected: https://recommender-test-4.azurewebsites.net/api/GetRecommendations?code=GHvuTHyv5jd5EsTK44lwQgwTQEwk2PbI6zkS7rugaVVjM7dInG4SQA==
- Want to access from another app:
axios.get(`https://recommender-test-4.azurewebsites.net/api/GetRecommendations?code=GHvuTHyv5jd5EsTK44lwQgwTQEwk2PbI6zkS7rugaVVjM7dInG4SQA==`)
.then(res => {
const data = res.data.data.children.map(obj => obj.data);
console.log(`Response Data: ${data}` );
}).catch((err, res) => {
console.log(err);
});
-
Cors error:
-
Add
*
cors rule:
Expected behavior
At this point I would expect to see the error disappear.
Actual behavior
Request is going through, but error remains. So I can’t actually get the body out of the response.
Known workarounds
Apparently there is a way to add some headers directly to func.HttpResponse
to make this work? But I can’t figure it out…
I could do something like this in JavaScript?
module.exports = function (context, req) {
context.res = {
status: 200,
body: "Hello " + req.query.name,
headers: {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': 'True'
}
};
context.done();
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
CORS errors - HTTP - MDN Web Docs - Mozilla
If the CORS configuration isn't setup correctly, the browser console will present an error like "Cross-Origin Request Blocked: The Same ...
Read more >Understanding and Resolving CORS Error - Contentstack
CORS is implemented on the server-side; it cannot be reconfigured on the client-side. The CORS behavior, commonly termed as CORS error, is a...
Read more >3 Ways to Fix the CORS Error — and How the Access-Control ...
The error stems from a security mechanism that browsers implement called the same-origin policy. The same-origin policy fights one of the most ...
Read more >What Is a CORS Error and How to Fix It (3 Ways) - Bannerbear
As a CORS error occurs when the external API server doesn't return the HTTP headers required by the CORS standard, you can add...
Read more >CORS errors and how to solve them - Topcoder
Or, your API fails and shows a CORS error in the console. · This happens because the same-origin policy is part of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s the API reference for
azure.functions.HttpResponse
- https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions.httpresponse?view=azure-pythonYou can provide a
dict
for theheaders
field.Here’s an example:
Awesome thanks. Tacking on the below headers worked for me.
This will work fine for the demo, but it feels like this is redundant with setting CORS policies in portal.