Skip to content

Commit 84f5550

Browse files
committed
Trim down configuration variables
1 parent 0039cd1 commit 84f5550

File tree

3 files changed

+11
-54
lines changed

3 files changed

+11
-54
lines changed

index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,22 @@ dotenv.config();
1111
// import { keys } from './config/keys.js';
1212

1313
let EXCHANGE_RATE_APIKEY;
14-
let BASE_URI;
15-
let SAMPLE2_URI;
14+
let EXCHANGE_BASE_URI='https://v6.exchangerate-api.com/v6/';
1615
let WEATHERBIT_KEY;
17-
let WEATHERBIT_URI;
16+
let WEATHERBIT_URI='https://api.weatherbit.io/v2.0/';
1817
let GoogleclientID;
1918
let GoogleclientSecret;
2019
if (process.env.NODE_ENV === "production") {
2120
EXCHANGE_RATE_APIKEY = process.env.EXCHANGE_RATE_APIKEY;
22-
BASE_URI = process.env.EXCHANGE_BASE_URI;
23-
SAMPLE2_URI = process.env.SAMPLE2_URI;
2421
WEATHERBIT_KEY = process.env.WEATHERBIT_KEY;
25-
WEATHERBIT_URI = process.env.WEATHERBIT_URI;
2622
GoogleclientID = process.env.GoogleclientID;
2723
GoogleclientSecret = process.env.GoogleclientSecret;
2824

2925
} else {
3026
// dynamically importing keys.js using promise:
3127
import('./config/keys.js').then((secrets) => {
3228
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;
3529
WEATHERBIT_KEY = secrets.keys.weatherbitapi.WEATHERBIT_APIKEY;
36-
WEATHERBIT_URI = secrets.keys.weatherbitapi.WEATHERBIT_BASE_URI;
3730
GoogleclientID = secrets.keys.google.clientID;
3831
GoogleclientSecret = secrets.keys.google.clientSecret;
3932
});
@@ -103,4 +96,4 @@ app.listen(port, () => {
10396
}
10497
});
10598

106-
export { EXCHANGE_RATE_APIKEY, BASE_URI, SAMPLE2_URI, WEATHERBIT_KEY, WEATHERBIT_URI, GoogleclientID, GoogleclientSecret };
99+
export { EXCHANGE_RATE_APIKEY, EXCHANGE_BASE_URI, WEATHERBIT_KEY, WEATHERBIT_URI, GoogleclientID, GoogleclientSecret };

routes/currency-exchange-routes.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import { data as currencyCodes } from 'currency-codes';
22
import request from 'request';
33
import express from 'express';
4-
import { EXCHANGE_RATE_APIKEY, BASE_URI, SAMPLE2_URI } from '../index.js';
4+
import { EXCHANGE_RATE_APIKEY, EXCHANGE_BASE_URI } from '../index.js';
55

6-
// let EXCHANGE_RATE_APIKEY;
7-
// let BASE_URI;
8-
// let SAMPLE2_URI;
9-
// if (process.env.NODE_ENV === "production") {
10-
// EXCHANGE_RATE_APIKEY = process.env.EXCHANGE_RATE_APIKEY;
11-
// BASE_URI = process.env.EXCHANGE_BASE_URI;
12-
// SAMPLE2_URI = process.env.SAMPLE2_URI;
13-
// } else {
14-
// EXCHANGE_RATE_APIKEY = keys.exchangerateapi.APIKEY;
15-
// BASE_URI = keys.exchangerateapi.BASE_URI;
16-
// SAMPLE2_URI = keys.exchangerateapi.SAMPLE2_URI;
17-
// }
186

197
const router = express.Router();
208

@@ -46,11 +34,11 @@ router.post('/', (req, res) => {
4634
function getExchangeRateData(fromCurrency, toCurrency, amount) {
4735
return new Promise(resolve => {
4836
setTimeout(() => {
49-
let URLStr = BASE_URI + EXCHANGE_RATE_APIKEY + '/pair/' + fromCurrency + '/' + toCurrency + '/' + amount;
37+
let URLStr = EXCHANGE_BASE_URI + EXCHANGE_RATE_APIKEY + '/pair/' + fromCurrency + '/' + toCurrency + '/' + amount;
5038
console.log(URLStr);
5139
try {
5240
if (fromCurrency === undefined) {
53-
URLStr = SAMPLE2_URI;
41+
URLStr = EXCHANGE_BASE_URI + EXCHANGE_RATE_APIKEY + '/pair/EUR/GBP/1';
5442
}
5543
console.log("Calling URL: " + URLStr);
5644
request(URLStr, async function (err, response, body) {

routes/weatherbit-routes.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,11 @@ function getWeatherAlerts(city){
5353
city = "&city=" + city;
5454
}
5555

56-
var Xcode = "";
57-
if (process.env.NODE_ENV === 'awsdeploy') {
58-
Xcode = JSON.parse(decryptAES(WEATHERBIT_KEY)).text;
59-
} else {
60-
Xcode = WEATHERBIT_KEY;
61-
}
56+
6257

6358
setTimeout(() => {
6459
// https://api.weatherbit.io/v2.0/alerts?lat=39.75895&lon=-84.19161&key=API_KEY
65-
let uriWeatherBitStr = `${WEATHERBIT_URI}alerts?units=I${city}&key=${Xcode}`;
60+
let uriWeatherBitStr = `${WEATHERBIT_URI}alerts?units=I${city}&key=${WEATHERBIT_KEY}`;
6661
let retCode;
6762
if (WEATHERBIT_URI.length === 0) {
6863
console.log('Failed to get API URI!');
@@ -107,16 +102,10 @@ function getWeatherAlerts(city){
107102
city = "&city=" + city;
108103
}
109104

110-
var Xcode = "";
111-
if (process.env.NODE_ENV === 'awsdeploy') {
112-
Xcode = JSON.parse(decryptAES(WEATHERBIT_KEY)).text;
113-
} else {
114-
Xcode = WEATHERBIT_KEY;
115-
}
116105

117106
setTimeout(() => {
118107

119-
let uriWeatherBitStr = `${WEATHERBIT_URI}current?units=I${city}&key=${Xcode}`;
108+
let uriWeatherBitStr = `${WEATHERBIT_URI}current?units=I${city}&key=${WEATHERBIT_KEY}`;
120109
let retCode;
121110
if (WEATHERBIT_URI.length === 0) {
122111
console.log('Failed to get aws secrets!');
@@ -159,15 +148,8 @@ function getWeatherAlerts(city){
159148
city = "&city=" + city;
160149
}
161150

162-
var Xcode = "";
163-
if (process.env.NODE_ENV === 'awsdeploy') {
164-
Xcode = JSON.parse(decryptAES(WEATHERBIT_KEY)).text;
165-
} else {
166-
Xcode = WEATHERBIT_KEY;
167-
}
168-
169151
setTimeout(() => {
170-
let uriWeatherBitStr = `${WEATHERBIT_URI}forecast/daily?units=I${city}&key=${Xcode}`;
152+
let uriWeatherBitStr = `${WEATHERBIT_URI}forecast/daily?units=I${city}&key=${WEATHERBIT_KEY}`;
171153
let retCode;
172154
// console.log(uriWeatherBitStr);
173155
try {
@@ -204,12 +186,6 @@ function getWeatherAlerts(city){
204186
city = "?city=" + city;
205187
}
206188

207-
var Xcode = "";
208-
if (process.env.NODE_ENV === 'awsdeploy') {
209-
Xcode = JSON.parse(decryptAES(WEATHERBIT_KEY)).text;
210-
} else {
211-
Xcode = WEATHERBIT_KEY;
212-
}
213189

214190
setTimeout(() => {
215191
let e = new Date().toISOString().slice(0, 16).replace('T', ' ')
@@ -221,7 +197,7 @@ function getWeatherAlerts(city){
221197
let startdate = s.split(' ')[0];
222198

223199
let retCode;
224-
let uriWeatherBitAPIStr = `${WEATHERBIT_URI}history/airquality${city}&start_date=${startdate}&end_date=${enddate}&key=${Xcode}`;
200+
let uriWeatherBitAPIStr = `${WEATHERBIT_URI}history/airquality${city}&start_date=${startdate}&end_date=${enddate}&key=${WEATHERBIT_KEY}`;
225201

226202
// console.log(uriWeatherBitAPIStr);
227203
try {

0 commit comments

Comments
 (0)