Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Config Variables for React-Native Apps
Search
Pedro Belo
February 24, 2016
Programming
0
730
Config Variables for React-Native Apps
Pedro Belo
February 24, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
Exploring the Implementation of “t.Run”, “t.Parallel”, and “t.Cleanup”
akarin
1
100
2 週間で Twitter Bot を作ってみた
contour_gara
0
740
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
160
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
300
SIMD Parallel Programming with the Vector API
josepaumard
0
220
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
8
1.3k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
1.7k
雑に思考を整理する技術と効能
konifar
61
30k
Domain-Driven Transformation
hschwentner
2
1.5k
ゆるい個人開発のススメ
kuroppe1819
10
1k
Java 22 Overview
kishida
1
190
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
390
Featured
See All Featured
Bash Introduction
62gerente
605
210k
The Straight Up "How To Draw Better" Workshop
denniskardys
228
130k
Agile that works and the tools we love
rasmusluckow
325
20k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Code Reviewing Like a Champion
maltzj
515
39k
Build your cross-platform service in a week with App Engine
jlugia
226
17k
Ruby is Unlike a Banana
tanoku
96
10k
StorybookのUI Testing Handbookを読んだ
zakiyama
13
4.6k
Embracing the Ebb and Flow
colly
80
4.2k
Into the Great Unknown - MozCon
thekraken
14
1k
Building an army of robots
kneath
300
41k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Transcript
Config Variables for React-Native apps
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 }); // ... };
The problem(s) • Secret in repo • Hard to change
• Can’t reuse outside JS
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 }); // ... };
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;
Solving #3 android { productFlavors { dev { resValue "string",
"GOOGLE_MAPS_API_KEY", "abcdefg" } production { resValue "string", "GOOGLE_MAPS_API_KEY", "0123456" } } }
Solving #3
New problems • Inconsistent formats • Need a React Native
bridge • Can’t reuse across platforms
SOLVE ALL THE THINGS $ rnpm install react-native-config
.env API_URL=https://api.lugg.com API_TOKEN=48616d6d65 GOOGLE_MAPS_API_KEY=0123456
Consume from JS import Config from 'react-native-config' Config.API_URL // https://api.lugg.com
Config.API_TOKEN // 48616d6d65
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") } } }
Consume from AndroidManifest.xml <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/GOOGLE_MAPS_API_KEY" />
Consume from Xcode
Thanks! @ped github.com/luggg/react-native-config