0
axios.get("https://url.example.com/b/478L", {
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'application/json',
        }
    }).then((response) => console.log(response.data))
        .catch((error) => console.log(error))

My URL is different.

Error:

Access to XMLHttpRequest at 'https://url.example.com/b/478L' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

James Z
  • 12,209
  • 10
  • 24
  • 44
Prem Jogi
  • 57
  • 8

2 Answers2

1

I don't know how server is built. But every back-end frameworks have functionality to handle CORS. For example, in ExpressJS, you can use cors middleware to handle CORS policy. So try to solve that problem on Server Side.

devastro
  • 79
  • 3
0

If you have your own back end you can solve this problem. For an example in Node/Express back end you can use cors library npm link here

Then in your app.js add this line,

//IMPORT THE LIBRARY
const cors = require('cors');


//ALLOW REQUEST FROM ANY DOMAIN
app.use(cors());

Will fix the error.

If are keep getting this error try different end-point. Or may be you find some thing useful here

Shihara Dilshan
  • 193
  • 2
  • 14