0

We have tow environments, Testing, and Production

We use Testing in two different scenarios; on our local devices, and when we have our app deployed to TestFlight for our remote users to test.

We differentiate between our two domains manually within our config.js file :

const domain = 'testing-server.herokuapp.com'; // 'actualWebsite.com';

So once everything is all set to go, we change the site to actualWebsite.com and deploy. But! Is there anyway to make this ENV aware, so that it just knows it was on production and therefore would automagically point to actualWebsite.com and if it was on TestFlight or on our local, it would automagically use testing-server.herokuapp.com ?

Trip
  • 26,756
  • 46
  • 158
  • 277

1 Answers1

0
const domain = process.env.NODE_ENV === 'development' ? 'testing-server.herokuapp.com' : 'actualWebsite.com';

Alternatively you can install babel-plugin-transform-inline-environment-variables and declare domain as an environment variable, and set a different environment variable value in your build tool.

react-native-config is another choice.

Roy Wang
  • 11,112
  • 2
  • 21
  • 42
  • `process.env.NODE_ENV` won't differentiate between TestFlight and Production – Trip May 04 '18 at 14:28
  • @trip What will then? – pfg May 04 '18 at 14:31
  • 1
    You can create a native module and bridge it to RN to check for TestFlight if you really need that. See https://stackoverflow.com/questions/26081543/how-to-tell-at-runtime-whether-an-ios-app-is-running-through-a-testflight-beta-i – Roy Wang May 04 '18 at 14:33
  • You can also set the `process.env` in your build command for TestFlight, but this means you have to re-build it for production (instead of just moving it from TestFlight to production), which is not a very good idea imo. – Roy Wang May 04 '18 at 14:35