Skip to content

Commit ed4a4be

Browse files
Merge pull request #60 from hurricanemark/Phase4-TeamRolEmiSeriousWorks
Dynamically import config keys.js
2 parents 1e71c67 + e82fc7b commit ed4a4be

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import {encryptAES, decryptAES} from './crypto.js';
77
// dev env
88
dotenv.config();
99

10+
// application secrets
11+
// import { keys } from './config/keys.js';
12+
1013
let EXCHANGE_RATE_APIKEY;
1114
let BASE_URI;
1215
let SAMPLE2_URI;
1316
let WEATHERBIT_KEY;
1417
let WEATHERBIT_URI;
1518
let GoogleclientID;
1619
let GoogleclientSecret;
17-
// if (process.env.NODE_ENV === "production") {
20+
if (process.env.NODE_ENV === "production") {
1821
EXCHANGE_RATE_APIKEY = process.env.EXCHANGE_RATE_APIKEY;
1922
BASE_URI = process.env.EXCHANGE_BASE_URI;
2023
SAMPLE2_URI = process.env.SAMPLE2_URI;
@@ -23,25 +26,25 @@ let GoogleclientSecret;
2326
GoogleclientID = process.env.GoogleclientID;
2427
GoogleclientSecret = process.env.GoogleclientSecret;
2528

26-
//} else {
27-
// // dynamically importing keys.js:
28-
// let AppKeys = await import('./config/keys.js');
29-
// EXCHANGE_RATE_APIKEY = AppKeys.exchangerateapi.APIKEY;
30-
// BASE_URI = AppKeys.exchangerateapi.BASE_URI;
31-
// SAMPLE2_URI = AppKeys.exchangerateapi.SAMPLE2_URI;
32-
// WEATHERBIT_KEY = AppKeys.weatherbitapi.APIKEY;
33-
// WEATHERBIT_URI = AppKeys.weatherbitapi.BASE_URI;
34-
// GoogleclientID = AppKeys.google.clientID;
35-
// GoogleclientSecret = AppKeys.google.clientSecre;
36-
// }
29+
} else {
30+
// dynamically importing keys.js using promise:
31+
import('./config/keys.js').then((secrets) => {
32+
EXCHANGE_RATE_APIKEY = secrets.keys.exchangerateapi.EXCHANGE_APIKEY;
33+
BASE_URI = secrets.keys.exchangerateapi.EXCHANGE_BASE_URI;
34+
SAMPLE2_URI = secrets.keys.exchangerateapi.SAMPLE2_URI;
35+
WEATHERBIT_KEY = secrets.keys.weatherbitapi.WEATHERBIT_APIKEY;
36+
WEATHERBIT_URI = secrets.keys.weatherbitapi.WEATHERBIT_BASE_URI;
37+
GoogleclientID = secrets.keys.google.clientID;
38+
GoogleclientSecret = secrets.keys.google.clientSecret;
39+
});
40+
41+
}
3742

3843

3944

4045
// Create network routing
4146
const app = express();
4247

43-
// application secrets
44-
import { keys } from './config/keys.js';
4548

4649
// routes handler for Currency Exchange methods
4750
import { router as currencyExchangeRoutes } from './routes/currency-exchange-routes.js';

0 commit comments

Comments
 (0)