Netflix / falcor

A JavaScript library for efficient data fetching
http://netflix.github.io/falcor
Apache License 2.0
10.48k stars 445 forks source link

cannot setup react-native with falcor #740

Open almeynman opened 8 years ago

almeynman commented 8 years ago

I have removed asap dependencies from falcor master branch, and it does work with cache. But when I include source: new FalcorHttpDatasource('http://localhost:9090') data is not received. Not sure what is the problem. With falcor v0.1.15: source: new FalcorHttpDatasource('http://localhost:9090/model.json') was enough to make it work

UPDATE Forgot to mention that I also use falcor-http-datasource master branch no the latest release version.

przeor commented 8 years ago

@almasakchabayev have you checked the CORS? I dunno, maybe it may be the case as React-Native runs on other posts than the backend (I believe).

almeynman commented 8 years ago

@przeor I think the problem is with CORS. because in the browser (webpack-dev-server also runs on a different port) I had to do add the following to the datasource:

  source: new FalcorHttpDatasource('http://localhost:9090/model.json', {
    withCredentials: false,
    crossDomain: true
  }),

and in the server I have added app.use(cors({ origin: '*' })); WIth this setup falcor works in browser with webpack-dev-server being on a different port. However similar setup does not seem to be working in React Native

przeor commented 8 years ago

@almasakchabayev have you got it right? If yes, please share solution for others ;-)

przeor commented 8 years ago

please also ping me on email kamil@przeorski.pl - @almasakchabayev, I have got some questions based on your GH profile about relay and falcor ;-)

almeynman commented 8 years ago

@przeor No I have not. But really did not really try anything else.

kcole16 commented 8 years ago

I got it to work by changing this file: https://github.com/Netflix/falcor-http-datasource/blob/master/src/getCORSRequest.js.

'use strict'; // Get CORS support even for older IE module.exports = function getCORSRequest() { var xhr = new global.XMLHttpRequest(); if ('withCredentials' in xhr) { return xhr; } else if (!!global.XDomainRequest) { return new XDomainRequest(); } else { +++return xhr; --- throw new Error('CORS is not supported by your browser'); } };

raecoo commented 8 years ago

@kcole16 Thanks for your sharing. It resolved our problem. 👍

yorzi commented 8 years ago

@kcole16 Your solution saved me a day. Thank you!!