Skip to content

Commit 2fa7be0

Browse files
committed
Merge branch '7-gerer-la-configuration' into 'master'
Resolve "Gérer la configuration" Closes #7 See merge request tcm-projects/react-native-boilerplate!15
2 parents 26747f8 + 1256b22 commit 2fa7be0

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

App/Config/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
index.js

App/Config/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
This directory contains configuration variables in 3 files:
2+
- `index.dev.js` : contains development variables
3+
- `index.production.js` : contains production variables
4+
- `index.staging.js` : contains beta tests variables
5+
6+
You need to create `index.js` by copying the right file.
7+
8+
#### Warning
9+
Each time you need to build, you need to verify if your `index.js` is the right one.
10+
For example, during development, before building your app do:
11+
```
12+
cp App\Config\index.dev.js App\Config\index.js
13+
```
14+
In other environment, you must pay attention to change your `index.js` with the good one.
15+
Also, make sure you add each configuration variable in each configuration file.
16+
17+
#### Usage
18+
```
19+
import Config from 'App/Config'
20+
21+
...
22+
let uri = Config.API_URL
23+
...
24+
25+
```

App/Config/index.dev.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const Config = {
2+
API_URL: 'https://query.yahooapis.com/v1/public/',
3+
API_PREFIX: 'api',
4+
}

App/Config/index.production.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const Config = {
2+
API_URL: 'https://query.yahooapis.com/v1/public/',
3+
API_PREFIX: 'api',
4+
}

App/Config/index.staging.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const Config = {
2+
API_URL: 'https://query.yahooapis.com/v1/public/',
3+
API_PREFIX: 'api',
4+
}

App/Service/WeatherService.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { create } from 'apisauce'
2+
import { Config } from 'App/Config'
23

34
const weatherApiClient = create({
4-
baseURL: 'https://query.yahooapis.com/v1/public/',
5+
baseURL: Config.API_URL,
56
headers: {
67
Accept: 'application/json',
78
'Content-Type': 'application/json',

0 commit comments

Comments
 (0)