Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit add731e

Browse files
authored
add environments config (#28)
* add environments config
1 parent e20087a commit add731e

File tree

8 files changed

+60
-2
lines changed

8 files changed

+60
-2
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"predev": "npm run removeAndBuildServer",
1818
"dev": "npm run watchServer & npm run devServer",
1919
"devWindows": "concurrently --kill-others \"npm run watchServer\" \"npm run devServer\"",
20-
"devServer": "cross-env NODE_ENV=development nodemon ./dist/server.js",
20+
"devServer": "cross-env NODE_ENV=staging nodemon ./dist/server.js",
2121
"---------- LOCAL -----------------------------------------------------------------------------": "",
2222
"prelocal": "npm run removeAndBuildServer",
2323
"local": "npm run watchServer & npm run localServer",
@@ -66,6 +66,7 @@
6666
"@types/hapi": "17.6.3",
6767
"@types/inert": "5.1.2",
6868
"@types/jest": "23.3.9",
69+
"@types/module-alias": "2.0.0",
6970
"@types/node": "10.12.9",
7071
"@types/node-notifier": "0.0.28",
7172
"@types/react": "16.4.18",
@@ -119,6 +120,7 @@
119120
"hapi-webpack-plugin": "3.0.0",
120121
"history": "4.7.2",
121122
"inert": "5.1.2",
123+
"module-alias": "2.1.0",
122124
"node-notifier": "5.3.0",
123125
"react": "16.6.3",
124126
"react-async-bootstrapper": "2.1.1",

src/environments/local.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import environment from './production';
2+
3+
export default {
4+
endpointUrl: {
5+
...environment.endpointUrl,
6+
// override any endpoints
7+
},
8+
isProduction: false,
9+
};

src/environments/production.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
endpointUrl: {
3+
randomuser: 'https://randomuser.me/api',
4+
},
5+
isProduction: true,
6+
};

src/environments/staging.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import environment from './production';
2+
3+
export default {
4+
endpointUrl: {
5+
...environment.endpointUrl,
6+
// override any endpoints
7+
},
8+
isProduction: false,
9+
};

src/server.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* module-alias is used to resolve the environment path for node files.
3+
*
4+
* // import environment from 'environment';
5+
*/
6+
import * as moduleAlias from 'module-alias';
7+
moduleAlias.addAliases({
8+
environment: `${__dirname}/environments/${process.env.NODE_ENV}.js`,
9+
});
10+
111
import 'fetch-everywhere';
212
import * as inert from 'inert';
313
import AssetsController from './server/controllers/AssetsController';

src/stores/user/UserService.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import HttpUtility from '../../utilities/HttpUtility';
22
import {AxiosResponse} from 'axios';
33
import IUser from './models/IUser';
4+
import environment from 'environment';
45

56
export default class UserService {
67

78
private static _http: HttpUtility = new HttpUtility();
89

910
public static async loadUser(): Promise<IUser> {
10-
const endpoint: string = 'https://randomuser.me/api/?inc=picture,name,email,phone,id,dob';
11+
const endpoint: string = `${environment.endpointUrl.randomuser}?inc=picture,name,email,phone,id,dob`;
1112
const response: AxiosResponse = await UserService._http.get(endpoint);
1213

1314
return response.data.results[0];

src/typings.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ declare module 'form2js';
1515
declare module 'react-async-bootstrapper';
1616
declare module 'react-async-component';
1717
declare module 'hapi-webpack-plugin';
18+
19+
declare module 'environment' {
20+
const value: {
21+
isProduction: boolean;
22+
endpointUrl: {
23+
randomuser: string;
24+
}
25+
};
26+
27+
export default value;
28+
}

yarn.lock

+10
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,11 @@
887887
dependencies:
888888
"@types/mime-db" "*"
889889

890+
"@types/module-alias@2.0.0":
891+
version "2.0.0"
892+
resolved "https://registry.yarnpkg.com/@types/module-alias/-/module-alias-2.0.0.tgz#882668f8b8cdbda44812c3b592c590909e18849e"
893+
integrity sha512-e3sW4oEH0qS1QxSfX7PT6xIi5qk/YSMsrB9Lq8EtkhQBZB+bKyfkP+jpLJRySanvBhAQPSv2PEBe81M8Iy/7yg==
894+
890895
"@types/node-notifier@0.0.28":
891896
version "0.0.28"
892897
resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-0.0.28.tgz#86ba3d3aa8d918352cc3191d88de328b20dc93c1"
@@ -5625,6 +5630,11 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
56255630
dependencies:
56265631
minimist "0.0.8"
56275632

5633+
module-alias@2.1.0:
5634+
version "2.1.0"
5635+
resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.1.0.tgz#c36d4fd15f7f9d7112f62fa015385e7b65a286c1"
5636+
integrity sha1-w21P0V9/nXES9i+gFThee2WihsE=
5637+
56285638
moment@^2.22.1:
56295639
version "2.22.2"
56305640
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"

0 commit comments

Comments
 (0)