Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Config Variables for React-Native Apps

Pedro Belo
February 24, 2016

Config Variables for React-Native Apps

Pedro Belo

February 24, 2016
Tweet

Other Decks in Programming

Transcript

  1. The problem var LuggApi = { request: async function(method, path)

    { let url = 'https://api.lugg.com' + path; let headers = { 'Authorization': 'Bearer 48616d6d65'} let response = await fetch(url, { method, headers }); // ... };
  2. Solving #1 // config.sample.js module.exports = { apiUrl: 'https://api.lugg.com', apiToken:

    'CHANGEME' } // api.js var LuggApi = { request: async function(method, path) { let url = Config.apiUrl + path; let headers = { 'Authorization': 'Bearer ' + Config.apiToken } let response = await fetch(url, { method, headers }); // ... };
  3. Solving #2 // config.js var dev = { apiUrl: 'http://localhost:5000',

    apiToken: 'abcdefgh' }; var prod = { apiUrl: 'https://api.lugg.com', apiToken: '48616d6d65' }; module.exports = __DEV__ ? dev : prod;
  4. Solving #3 android { productFlavors { dev { resValue "string",

    "GOOGLE_MAPS_API_KEY", "abcdefg" } production { resValue "string", "GOOGLE_MAPS_API_KEY", "0123456" } } }
  5. New problems • Inconsistent formats • Need a React Native

    bridge • Can’t reuse across platforms
  6. Consume from Gradle android { signingConfigs { release { storeFile

    file(project.env.get("RELEASE_STORE_FILE")) storePassword project.env.get("RELEASE_STORE_PASSWORD") keyAlias project.env.get("RELEASE_KEY_ALIAS") keyPassword project.env.get("RELEASE_KEY_PASSWORD") } } }