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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Pedro Belo
February 24, 2016
Programming
740
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Config Variables for React-Native Apps
Pedro Belo
February 24, 2016
Other Decks in Programming
See All in Programming
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
7.3k
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.9k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
200
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
Oxlintのカスタムルールの現況
syumai
6
1.1k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
550
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
150
Contextとはなにか
chiroruxx
1
350
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
120
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
280
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.7k
AIで効率化できた業務・日常
ochtum
0
140
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
210
Making Projects Easy
brettharned
120
6.7k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
210
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Tell your own story through comics
letsgokoyo
1
960
GitHub's CSS Performance
jonrohan
1033
470k
A Soul's Torment
seathinner
6
3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
Designing for Timeless Needs
cassininazir
1
260
Exploring anti-patterns in Rails
aemeredith
3
420
A Modern Web Designer's Workflow
chriscoyier
698
190k
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