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

add environments config #28

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"predev": "npm run removeAndBuildServer",
"dev": "npm run watchServer & npm run devServer",
"devWindows": "concurrently --kill-others \"npm run watchServer\" \"npm run devServer\"",
"devServer": "cross-env NODE_ENV=development nodemon ./dist/server.js",
"devServer": "cross-env NODE_ENV=staging nodemon ./dist/server.js",
"---------- LOCAL -----------------------------------------------------------------------------": "",
"prelocal": "npm run removeAndBuildServer",
"local": "npm run watchServer & npm run localServer",
Expand Down Expand Up @@ -66,6 +66,7 @@
"@types/hapi": "17.6.3",
"@types/inert": "5.1.2",
"@types/jest": "23.3.9",
"@types/module-alias": "2.0.0",
"@types/node": "10.12.9",
"@types/node-notifier": "0.0.28",
"@types/react": "16.4.18",
Expand Down Expand Up @@ -119,6 +120,7 @@
"hapi-webpack-plugin": "3.0.0",
"history": "4.7.2",
"inert": "5.1.2",
"module-alias": "2.1.0",
"node-notifier": "5.3.0",
"react": "16.6.3",
"react-async-bootstrapper": "2.1.1",
Expand Down
9 changes: 9 additions & 0 deletions src/environments/local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import environment from './production';

export default {
endpointUrl: {
...environment.endpointUrl,
// override any endpoints
},
isProduction: false,
};
6 changes: 6 additions & 0 deletions src/environments/production.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
endpointUrl: {
randomuser: 'https://randomuser.me/api',
},
isProduction: true,
};
9 changes: 9 additions & 0 deletions src/environments/staging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import environment from './production';

export default {
endpointUrl: {
...environment.endpointUrl,
// override any endpoints
},
isProduction: false,
};
10 changes: 10 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* module-alias is used to resolve the environment path for node files.
*
* // import environment from 'environment';
*/
import * as moduleAlias from 'module-alias';
moduleAlias.addAliases({
environment: `${__dirname}/environments/${process.env.NODE_ENV}.js`,
});

import 'fetch-everywhere';
import * as inert from 'inert';
import AssetsController from './server/controllers/AssetsController';
Expand Down
3 changes: 2 additions & 1 deletion src/stores/user/UserService.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import HttpUtility from '../../utilities/HttpUtility';
import {AxiosResponse} from 'axios';
import IUser from './models/IUser';
import environment from 'environment';

export default class UserService {

private static _http: HttpUtility = new HttpUtility();

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

return response.data.results[0];
Expand Down
11 changes: 11 additions & 0 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ declare module 'form2js';
declare module 'react-async-bootstrapper';
declare module 'react-async-component';
declare module 'hapi-webpack-plugin';

declare module 'environment' {
const value: {
isProduction: boolean;
endpointUrl: {
randomuser: string;
}
};

export default value;
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,11 @@
dependencies:
"@types/mime-db" "*"

"@types/module-alias@2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/module-alias/-/module-alias-2.0.0.tgz#882668f8b8cdbda44812c3b592c590909e18849e"
integrity sha512-e3sW4oEH0qS1QxSfX7PT6xIi5qk/YSMsrB9Lq8EtkhQBZB+bKyfkP+jpLJRySanvBhAQPSv2PEBe81M8Iy/7yg==

"@types/node-notifier@0.0.28":
version "0.0.28"
resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-0.0.28.tgz#86ba3d3aa8d918352cc3191d88de328b20dc93c1"
Expand Down Expand Up @@ -5625,6 +5630,11 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
dependencies:
minimist "0.0.8"

module-alias@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.1.0.tgz#c36d4fd15f7f9d7112f62fa015385e7b65a286c1"
integrity sha1-w21P0V9/nXES9i+gFThee2WihsE=

moment@^2.22.1:
version "2.22.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
Expand Down