Skip to content

Commit 120dbea

Browse files
Merge pull request #53 from hurricanemark/Phase4-TeamRolEmiSeriousWorks
Correcting build error on environment variables
2 parents 7b8b17b + 6ddbb4f commit 120dbea

File tree

7 files changed

+45
-30
lines changed

7 files changed

+45
-30
lines changed

index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import express from 'express';
44
import bodyParser from 'body-parser';
55
import {encryptAES, decryptAES} from './crypto.js';
66

7+
// dev env
8+
dotenv.config();
9+
10+
// Create network routing
11+
const app = express();
712

813
// application secrets
914
import { keys } from './config/keys.js';
@@ -14,11 +19,9 @@ import { router as currencyExchangeRoutes } from './routes/currency-exchange-rou
1419
// routes handler for WeatherBit.io API methods
1520
import { router as weatherbitRoutes } from './routes/weatherbit-routes.js';
1621

17-
// dev env
18-
dotenv.config();
22+
// routes handler for OAuth20 methods
23+
import { router as oauth20Routes } from './routes/auth-routes.js';
1924

20-
// Create network routing
21-
const app = express();
2225

2326
// EJS is accessed by default in the views directory.
2427
app.set('view engine', 'ejs');
@@ -35,6 +38,9 @@ app.use('/exchange', currencyExchangeRoutes);
3538
// Set up all routes to WeatherBit reports
3639
app.use('/weatherbit', weatherbitRoutes);
3740

41+
// Set up all routes related to oauth2 methods
42+
app.use('/auth', oauth20Routes);
43+
3844
// Homepage: get the locale from the client-side via the ejs form
3945
app.get('/', (req, res) => {
4046
res.render('index', {xkey: 'hey'});

models/user-models.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const mongoose = require('mongoose');
1+
import mongoose from 'mongoose';
22
const Schema = mongoose.Schema;
33

44
const userSchema = new Schema({
@@ -9,4 +9,5 @@ const userSchema = new Schema({
99

1010
const User = mongoose.model('user', userSchema);
1111

12-
module.exports = User;
12+
// module.exports = User;
13+
export { User };

routes/auth-routes.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const router = require('express').Router();
2-
const passport = require('passport');
3-
const { rawListeners } = require('../models/user-models');
1+
import express from 'express';
2+
import passport from 'passport';
43

54

5+
const router = express.Router();
6+
67
// auth login
78
router.get('/login', (req, res) => {
89
res.render('login', {user: req.user});
@@ -33,4 +34,4 @@ router.get('/google/redirect', passport.authenticate('google'), (req, res) => {
3334
});
3435

3536

36-
module.exports = router;
37+
export { router };

routes/currency-exchange-routes.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
import { data as currencyCodes } from 'currency-codes';
22
import request from 'request';
33
import express from 'express';
4+
45
import { keys } from '../config/keys.js';
6+
7+
let EXCHANGE_RATE_APIKEY;
8+
let BASE_URI;
9+
let SAMPLE2_URI;
10+
if (process.env.NODE_ENV === "production") {
11+
EXCHANGE_RATE_APIKEY = process.env.EXCHANGE_RATE_APIKEY;
12+
BASE_URI = process.env.BASE_URI;
13+
SAMPLE2_URI = process.env.SAMPLE2_URI;
14+
} else {
15+
EXCHANGE_RATE_APIKEY = keys.exchangerateapi.APIKEY;
16+
BASE_URI = keys.exchangerateapi.URI;
17+
SAMPLE2_URI = keys.exchangerateapi.SAMPLE2_URI;
18+
}
19+
520
const router = express.Router();
621

722

@@ -32,13 +47,11 @@ router.post('/', (req, res) => {
3247
function getExchangeRateData(fromCurrency, toCurrency, amount) {
3348
return new Promise(resolve => {
3449
setTimeout(() => {
35-
let XchangeKey = process.env.EXCHANGE_RATE_APIKEY;
36-
let XchangeURI = process.env.BASE_URI;
37-
let URLStr = XchangeURI + XchangeKey + '/pair/' + fromCurrency + '/' + toCurrency + '/' + amount;
38-
50+
let URLStr = BASE_URI + EXCHANGE_RATE_APIKEY + '/pair/' + fromCurrency + '/' + toCurrency + '/' + amount;
51+
console.log(URLStr);
3952
try {
4053
if (fromCurrency === undefined) {
41-
URLStr = process.env.SAMPLE2_URI;
54+
URLStr = SAMPLE2_URI;
4255
}
4356
console.log("Calling URL: " + URLStr);
4457
request(URLStr, async function (err, response, body) {

routes/weatherbit-routes.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import request from 'request';
33
import { keys } from '../config/keys.js';
44
const router = express.Router();
55

6-
let WEATHERBIT_KEY = keys.weatherbitapi.APIKEY;
7-
let WEATHERBIT_URI = keys.weatherbitapi.URI;
8-
6+
let WEATHERBIT_KEY;
7+
let WEATHERBIT_URI;
98

9+
if (process.env.NODE_ENV === "production") {
10+
WEATHERBIT_KEY = process.env.WEATHERBIT_KEY;
11+
WEATHERBIT_URI = process.env.WEATHERBIT_URI;
12+
} else {
13+
WEATHERBIT_KEY = keys.weatherbitapi.APIKEY;
14+
WEATHERBIT_URI = keys.weatherbitapi.URI;
15+
}
1016

1117
router.get('/', (req, res) => {
1218
res.render('pages/weatherbit');

views/index.ejs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<input type="hidden" id="xcree" name="xcree" value="ZTg4ZTFhODA5NmNkNDg5N2I3OWIyMzBhOWM0OWIyNDM=">
1717
<div id="geoLatLng" action="showPosition()">
1818
<!-- pinpoint positon verbish will be loaded into here -->
19-
<!-- <p><%= xkey %></p> -->
2019
</div>
2120
<hr>
2221
<p>Take the load off, sit down, look up. The weather is telling us something about our past actions. </p>

views/pages/utils.ejs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<%
22
const MOON = '🌙';
33
const SUN = '☀️';
4-
54
// convert unix_timestamp to local datetime
65
unixTsToLocalTime = (unix_ts) => {
76
// Create a new JavaScript Date object based on the timestamp
@@ -13,11 +12,9 @@ unixTsToLocalTime = (unix_ts) => {
1312
var minutes = "0" + date.getMinutes();
1413
// Seconds part from the timestamp
1514
var seconds = "0" + date.getSeconds();
16-
1715
// Will display time in 10:30:23 format
1816
return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
1917
}
20-
2118
trendingTemperature = (dataArr) => {
2219
var sum = 0;
2320
for (var item of dataArr) {
@@ -35,7 +32,6 @@ trendingTemperature = (dataArr) => {
3532
else { return "Considerable warming trend ahead."; }
3633
}
3734
}
38-
3935
// check if client allows saving session data
4036
storageAvailable = (type) => {
4137
let storage;
@@ -61,26 +57,21 @@ storageAvailable = (type) => {
6157
(storage && storage.length !== 0);
6258
}
6359
}
64-
6560
// save data to session memory client-side
6661
saveClientData = (key, value) => {
6762
if (storageAvailable(String)) {
6863
// Yippee! We can use localStorage awesomeness
6964
// Save data to sessionStorage
7065
sessionStorage.setItem(key, value);
71-
7266
// Get saved data from sessionStorage
7367
let data = sessionStorage.getItem(key);
74-
7568
alert(methodString +' says my data is ' + data);
76-
7769
}
7870
else {
7971
// Too bad, no localStorage for us
8072
alert(methodString + ' says Web Storage API is disabled.')
8173
}
8274
}
83-
8475
// retrieve saved session data
8576
getClientData = (key) => {
8677
if (storageAvailable(String)) {
@@ -89,11 +80,9 @@ getClientData = (key) => {
8980
return null;
9081
}
9182
}
92-
9383
// delete session data
9484
deleteClientData = (key) => {
9585
// Remove saved data from sessionStorage
9686
sessionStorage.removeItem(key);
9787
}
98-
9988
%>

0 commit comments

Comments
 (0)