11import 'babel-polyfill' ;
22import 'isomorphic-unfetch' ;
3- require ( 'dotenv' ) . config ( { path : 'variables.env' } ) ;
3+ import config from 'config' ;
44import path from 'path' ;
55import fs from 'fs' ;
66import express from 'express' ;
@@ -33,12 +33,15 @@ import { resolvers } from './src/resolvers';
3333import User from './src/models/User' ;
3434
3535// Connect MongoDB
36- mongoose . connect ( process . env . DB_CONNECTION_STRING , { useNewUrlParser : true } ) . then ( ( ) => {
36+ mongoose . connect ( config . get ( 'dbString' ) , { useNewUrlParser : true } ) . then ( ( ) => {
3737 console . log ( 'Connection to DB successful' ) ;
3838} ) . catch ( err => {
3939 console . log ( `Connection to DB Error: ${ err } ` ) ;
4040} ) ;
4141
42+ // check env vars
43+ require ( './config' ) ( ) ;
44+
4245const app = express ( ) ;
4346const PORT = process . env . PORT || 3000 ;
4447
@@ -76,7 +79,7 @@ app.use(async (req, res, next) => {
7679 const token = req . cookies . token ? req . cookies . token : null ;
7780 if ( token !== null ) {
7881 try {
79- const currentUser = await jwt . verify ( token , process . env . JWT_SECRET ) ;
82+ const currentUser = await jwt . verify ( token , config . get ( 'jwtPrivateKey' ) ) ;
8083 req . currentUser = currentUser ;
8184 } catch ( err ) {
8285 // console.error(err);
@@ -159,10 +162,10 @@ app.get(['*/:param', '*'], (req, res) => {
159162app . post ( '/password-reset' , ( req , response ) => {
160163
161164 var mailer = nodemailer . createTransport ( {
162- host : process . env . NODEMAILER_HOST ,
165+ host : config . get ( 'mailServer.host' ) ,
163166 auth : {
164- user : process . env . NODEMAILER_AUTH_USER ,
165- pass : process . env . NODEMAILER_AUTH_PW
167+ user : config . get ( 'mailServer.auth.user' ) ,
168+ pass : config . get ( 'mailServer.auth.pass' )
166169 }
167170 } ) ;
168171
@@ -172,9 +175,9 @@ app.post('/password-reset', (req, response) => {
172175 } ) ) ;
173176
174177 mailer . sendMail ( {
175- from : process . env . NODEMAILER_FROM_EMAIL ,
178+ from : config . get ( 'mailServer.from' ) ,
176179 to : req . body . email ,
177- subject : 'React Starter Kit - Password Reset' ,
180+ subject : config . get ( 'mailServer.subject' ) ,
178181 template : 'passwordReset' ,
179182 context : {
180183 email : req . body . email ,
0 commit comments