TheJediCowboy
TheJediCowboy

Reputation: 9232

How do I handle environment configuration in react-native to point at DEV/TEST/Production

I am new to RN and trying to figure out how I can utilize environment specific configuration.

For example, the code I have hitting my Server API needs to change based on the environment

const endpoint = "http://localhost:8282/api/v1/auth/"
//staging endpoint "http://staging:8282/api/v1/auth"
//production endpoint "http://production:8282/api/v1/auth"

    export default {
      login(fbId,fbAccessToken,expiresIn){
        return fetch(endpoint + 'login', {
          method: 'post',
          body: JSON.stringify({
            fb_id: fbId.toString(),
            access_token:fbAccessToken,
            expires:expiresIn.toString()
          })
        })
      }
    }

Upvotes: 0

Views: 130

Answers (1)

QoP
QoP

Reputation: 28397

You can check the value of __DEV__ in order to achieve that.

Your code should look like this

const endpoint = __DEV__  ? "http://staging:8282/api/v1/auth/"
                          : "http://production:8282/api/v1/auth"

Upvotes: 1

Related Questions