falcor icon indicating copy to clipboard operation
falcor copied to clipboard

cannot setup react-native with falcor

Open almeynman opened this issue 9 years ago • 8 comments

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.

almeynman avatar Feb 24 '16 11:02 almeynman

@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).

przeor avatar Feb 24 '16 12:02 przeor

@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

almeynman avatar Feb 24 '16 13:02 almeynman

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

przeor avatar Feb 25 '16 21:02 przeor

please also ping me on email [email protected] - @almasakchabayev, I have got some questions based on your GH profile about relay and falcor ;-)

przeor avatar Feb 25 '16 21:02 przeor

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

almeynman avatar Feb 26 '16 06:02 almeynman

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'); } };

kcole16 avatar May 01 '16 04:05 kcole16

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

raecoo avatar May 26 '16 02:05 raecoo

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

yorzi avatar May 26 '16 02:05 yorzi