Access-Control-Allow-Origin Error

0

I am trying to make a request from one server to another to perform a registration, but this error is always returned to me:

  

Failed to load link : Response to   preflight request does not pass access control check: No   'Access-Control-Allow-Origin' header is present on the requested   resource. Origin ' link ' is therefore not   allowed access.

My request looks like this:

var config = {
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
        'Access-Control-Allow-Headers': '*',
        'token': 'meu_token'
    }
};
this.$http.post('http://dominio_da_api/services/criarConta', this.dados, config).then(response => {

I used a chrome extension for CORS tests, when it is enabled it works normally, but when I disable it, it generates this error. I am using CodeIgniter and for the Vue-resource requests, I have also used the axios, but it returns the same error

    
asked by anonymous 29.12.2017 / 16:49

1 answer

0

I had a problem a while ago with this trying to make requests in the Google Maps API, and this error occurred in the front-end (Vuejs2), but through Postman it worked.

I did not understand the problem, but I solved this by first executing a request on my own back-end API that I had in the Laravel project, and Laravel was requesting the Google Maps API, and then returning to my front-end.

In this way, my front-end always stays accessing my back-end, and the back end becomes responsible for accessing third-party API (s).

I hope you have helped.

    
06.01.2018 / 16:01