Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

CORS issue Fetch API cannot load https://api.yelp.com #25

Closed
connor11528 opened this issue Jan 29, 2017 · 2 comments
Closed

CORS issue Fetch API cannot load https://api.yelp.com #25

connor11528 opened this issue Jan 29, 2017 · 2 comments

Comments

@connor11528
Copy link

I feel like this the most common AJAX issue in the world but I am running in to a cross origin request issue. I am using chrome browser. Do i need to set a request header or pass parameters?

What can I do in my javascript code to enable the request to the yelp API?

Thank you!

Code setup:

import Yelp from 'yelp'

const yelp = new Yelp({
  consumer_key: 'EYQr......vwA',
  consumer_secret: 'CrWS.......Smw0',
  token: '5knCxp........2M7cA9H',
  token_secret: 'sxpxA5........OKHYA',
});

yelp.search({ 
  term: 'food', 
  location: 'Montreal'
})
.then(function (data) {
  console.log(data);
})
.catch(function (err) {
  console.error(err);
});

Error text:

OPTIONS https://api.yelp.com/v2/search?term=food&location=Montreal 404 ()

localhost/:1 Fetch API cannot load https://api.yelp.com/v2/search?term=food&location=Montreal. 
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:8080' is therefore not allowed access. 
The response had HTTP status code 404. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Error image:

screen shot 2017-01-29 at 11 54 59 am

@connor11528
Copy link
Author

I am using vue.js and vue-resource so tried setting headers using that library to no avail

Vue.http.headers.common['Access-Control-Allow-Origin'] = '*'
Vue.http.headers.common['Access-Control-Allow-Headers'] = 'Content-Type,Authorization'
Vue.http.headers.common['Access-Control-Allow-Methods'] = 'GET'

It looks like we're using node-oauth to make the request. Not sure if we can set custom headers or what the deal is! ciaranj/node-oauth#243

@connor11528
Copy link
Author

Okay I think it is because this code is running on the client side and in order for this package to work it must only be on server side

Yelp/yelp-api#51

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

1 participant