1

On my localhost i create a react app (getting data from magento 2 rest api). Magento is set on vagrant so they are on other domains.

When I try to send request ...

   var uploadReq = new Request(LOGIN_URL, {
        method: 'post',
        headers: new Headers({
            'Content-Type': 'application/json',
        }),
        body: JSON.stringify({
            username: this.state.username,
            password: this.state.password
        })

    });

    fetch(uploadReq)
        .then(this._requestHandler)
        .catch(function (err) {
            console.log('Fetch Error :-S', err);
        });

.. I get an CORS error:

 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:3000' is therefore not allowed access. The response had HTTP status code 400. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I found this config example: https://enable-cors.org/server_nginx.html

But nothing has changed.

  • It's no Magento or NGINX issue, it's an issue related to JavaScript and HTTP Security protocol. I had this problem. – Rafael Corrêa Gomes Apr 7 '17 at 18:48
  • How did you solve this issue ? – Maciej Apr 8 '17 at 4:47
  • Uploading my files to server with https and domain. – Rafael Corrêa Gomes Apr 8 '17 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.