1
1
2
+ if ( process . env . NODE_ENV !== 'production' ) {
3
+ require ( 'dotenv' ) . config ( ) ;
4
+ }
5
+
2
6
const app = require ( 'express' ) ( ) ;
3
7
const http = require ( 'http' ) . createServer ( app ) ;
4
8
const io = require ( 'socket.io' ) ( http ) ;
5
9
const mongoClient = require ( "mongodb" ) . MongoClient ;
6
10
const axios = require ( 'axios' ) ;
7
11
8
- // TODO: use env variables instead
9
- const SECRETS = require ( './secrets' ) ;
10
- const CONNECTION_STRING = SECRETS . MONGO_CONNECTION_STRING ;
12
+ const PORT = process . env . PORT || 3000 ;
11
13
12
14
13
15
// For testing purposes only, will be creating a client in separate repo
@@ -22,15 +24,15 @@ app.get('/test2', function (req, res) {
22
24
23
25
var database , collection ;
24
26
25
- http . listen ( 3000 , function ( ) {
26
- console . log ( ' Listening on *:3000' ) ;
27
- mongoClient . connect ( CONNECTION_STRING , { useNewUrlParser : true , useUnifiedTopology : true } , ( error , client ) => {
27
+ http . listen ( PORT , function ( ) {
28
+ console . log ( ` Listening on *:${ PORT } ` ) ;
29
+ mongoClient . connect ( process . env . MONGO_CONNECTION_STRING , { useNewUrlParser : true , useUnifiedTopology : true } , ( error , client ) => {
28
30
if ( error ) {
29
31
throw error ;
30
32
}
31
- database = client . db ( SECRETS . MONGO_DB_NAME ) ;
32
- collection = database . collection ( SECRETS . MONGO_COLLECTION_NAME ) ;
33
- console . log ( ` Connected to database` ) ;
33
+ database = client . db ( process . env . MONGO_DB_NAME ) ;
34
+ collection = database . collection ( process . env . MONGO_COLLECTION_NAME ) ;
35
+ console . log ( ' Connected to database' ) ;
34
36
} ) ;
35
37
} ) ;
36
38
@@ -80,8 +82,8 @@ io.on('connection', function (socket) {
80
82
81
83
// fetch auth token and save to DB
82
84
axios . post ( 'http://qbquestionsapi.azurewebsites.net/api/authenticate' , {
83
- "username" : SECRETS . QBQUESTIONS_API_USERNAME ,
84
- "password" : SECRETS . QBQUESTIONS_API_PASSWORD
85
+ "username" : process . env . QBQUESTIONS_API_USERNAME ,
86
+ "password" : process . env . QBQUESTIONS_API_PASSWORD
85
87
} ) . then ( response => {
86
88
console . log ( response . data ) ;
87
89
0 commit comments