Is there a way to switch api url from development to production

时间:2018-07-24 10:01:59

标签: api react-native

I am currently building an app using react native. And I have quite a few screens in it. As the app is still in development stage I still hit localhost now. I am wondering if there is a way to switch these url's programmatically while developing vs in production. Also considering that developing still continues even after the app is published and in the play store. How do anyone handle this scenario? Or am I thinking it in the wrong way?

1 个答案:

答案 0 :(得分:0)

Try this code:

var url = '';

if (__DEV__) {
   url = 'http://localhost';
} else {
   url = 'http://exmple.com';
}