Reputation: 1488
I try to get data from API Google Places
axios.get('https://maps.googleapis.com/maps/api/place/details/json?placeid=...&key=mykey')
.then(response => {
commit('SET_REVIEWS', { list: response.data })
}, error => {
console.log(error)
})
And after that i have this error I know the error with CORS on server side, but what should i do?
Upvotes: 1
Views: 2964
Reputation: 1488
In my project I use NuxtJS and I found the solution.
You have to make a request on the server side (nodeJS), not the client.
As shown below, the method fetch allows you to do this and it works
https://nuxtjs.org/guide/vuex-store#the-fetch-method
Upvotes: 2
Reputation: 2472
Simply create and call a webservice on your own server which in turn calls googles webservice.
The main code of your webservice could look like this, in PHP:
$url = 'https://maps.googleapis.com/maps/api/place/details/json?key=' . $key . '&placeid=' . $place_id;
echo json_decode(file_get_contents($url), true);
Upvotes: 0