Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Conditionally set HttpLink URI #98

Open
DevanB opened this issue Feb 14, 2018 · 6 comments
Open

Conditionally set HttpLink URI #98

DevanB opened this issue Feb 14, 2018 · 6 comments

Comments

@DevanB
Copy link
Collaborator

DevanB commented Feb 14, 2018

There is an issue with fetch in React Native that prevents the usage of localhost.

A proposed solution is to use Platform.select to set the ApolloClient's HttpLink uri to one of several options:

const SERVER_URL = __DEV__
  ? Platform.select({
      ios: 'GET_USERS_IP_ADDRESS_AND_APPEND_PORT_4000',
      android: 'http://10.0.2.2:4000'
    })
  : 'USE_PRODUCTION_GRAPHQL_SERVER_ENV_VAR';

Android apparently allows 10.0.2.2 to equal localhost, but I haven't confirmed this myself.

@juicycleff
Copy link

Alright will handle this asap

@juicycleff
Copy link

Well android does not really, except you are using an emulator. For real device its different, it is based on the ip of the wifi connection which changes every time it restarts. But I will have a fix for that

@marktani
Copy link
Contributor

Is 127.0.0.1 supported instead, @DevanB?

@DevanB
Copy link
Collaborator Author

DevanB commented Feb 27, 2018

@marktani - apparently, no. It has to do with proxying through with Expo.

@devomacdee
Copy link

@DevanB did you end up finding a solution to this?

@DevanB
Copy link
Collaborator Author

DevanB commented Mar 27, 2018

@devomacdee unfortunately, no. I haven’t necessarily worked on it much too. The crux of the solution I proposed is figuring out the developer’s IP address when the env is development (don’t worry about production since that should be a separate url for a server).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants