Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios : Response to preflight request doesn't pass access control. #262

Closed
9tor opened this issue Mar 11, 2016 · 3 comments
Closed

axios : Response to preflight request doesn't pass access control. #262

9tor opened this issue Mar 11, 2016 · 3 comments

Comments

@9tor
Copy link

9tor commented Mar 11, 2016

I have an error when executing a get request in a ReactJs app does generate the following
"XMLHttpRequest cannot load http://localhost:3002/api/users. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3005' is therefore not allowed access. The response had HTTP status code 404."

My Code.

const ROOT_URL = 'http://localhost:3002';

const AUTH_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhb..................';

axios.defaults.baseURL = ROOT_URL;
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8';

axios.get('/api/users').then(function(response) {
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
});

@jamesblight
Copy link

This isn't an axios issue. You need to set your server to accept CORS requests. Look at the first answer to http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource

@9tor
Copy link
Author

9tor commented Mar 15, 2016

Hi,
I've already used it. by fixed at server added
"routes": {
"cors": true
}
at Hapi configuration connection
Thank you.

@devpedrofranco
Copy link

Hi @9tor have u resolve this problem?

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants