amino-health / oura-intervention

Web-application for the "Självständigt arbete inom IT" course
Mozilla Public License 2.0
1 stars 1 forks source link

Move the HTTP GET request to the backend #8

Open JakobPaulsson opened 2 years ago

JakobPaulsson commented 2 years ago

To avoid issues with CORS entirely, the following frontend code should be moved to the backend.:

var url = Uri.parse('http://api.ouraring.com/v1/userinfo?access_token=$token');
var response = await http.get(url, headers: {
    "Accept": "application/json",
    "Access-Control-Allow-Origin": "*"
});

This can be transformed into equivalent code in javascript:

axios.get('https://api.ouraring.com/v1/userinfo?access_token=${access_token}')
  .then(res => {
    console.log(`statusCode: ${res.status}`)
    console.log(res)
  })
  .catch(error => {
    console.error(error)
  })