Skip to content

Commit

Permalink
Merge branch '7-gerer-la-configuration' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Gérer la configuration"

Closes thecodingmachine#7

See merge request tcm-projects/react-native-boilerplate!15
  • Loading branch information
aum-tcm committed Aug 29, 2018
2 parents 26747f8 + 1256b22 commit 2fa7be0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions App/Config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.js
25 changes: 25 additions & 0 deletions App/Config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This directory contains configuration variables in 3 files:
- `index.dev.js` : contains development variables
- `index.production.js` : contains production variables
- `index.staging.js` : contains beta tests variables

You need to create `index.js` by copying the right file.

#### Warning
Each time you need to build, you need to verify if your `index.js` is the right one.
For example, during development, before building your app do:
```
cp App\Config\index.dev.js App\Config\index.js
```
In other environment, you must pay attention to change your `index.js` with the good one.
Also, make sure you add each configuration variable in each configuration file.

#### Usage
```
import Config from 'App/Config'
...
let uri = Config.API_URL
...
```
4 changes: 4 additions & 0 deletions App/Config/index.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const Config = {
API_URL: 'https://query.yahooapis.com/v1/public/',
API_PREFIX: 'api',
}
4 changes: 4 additions & 0 deletions App/Config/index.production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const Config = {
API_URL: 'https://query.yahooapis.com/v1/public/',
API_PREFIX: 'api',
}
4 changes: 4 additions & 0 deletions App/Config/index.staging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const Config = {
API_URL: 'https://query.yahooapis.com/v1/public/',
API_PREFIX: 'api',
}
3 changes: 2 additions & 1 deletion App/Service/WeatherService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { create } from 'apisauce'
import { Config } from 'App/Config'

const weatherApiClient = create({
baseURL: 'https://query.yahooapis.com/v1/public/',
baseURL: Config.API_URL,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Expand Down

0 comments on commit 2fa7be0

Please sign in to comment.