Skip to content

Commit

Permalink
changes for localhost mysql and verification email
Browse files Browse the repository at this point in the history
  • Loading branch information
mauryakrishna committed Nov 16, 2020
1 parent c0a7b2c commit 76d35b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
6 changes: 4 additions & 2 deletions database.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"defaultEnv": {"ENV": "NODE_ENV"},
"defaultEnv": {
"ENV": "NODE_ENV"
},
"development": {
"driver": "mysql",
"host": "mysql",
"host": "localhost",
"port": "3306",
"user": "newuser",
"password": "password",
Expand Down
2 changes: 1 addition & 1 deletion devenv.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NODE_ENV": "development",
"PORT": 4000,
"MYSQL_USER": "newuser",
"MYSQL_HOST": "mysql",
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_PASSWORD": "password",
"MYSQL_DATABASE": "exp",
Expand Down
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (process.env.NODE_ENV == 'development') {
if (process.env.NODE_ENV == 'development') {
require('env2')('./devenv.json');
}
else {
Expand Down Expand Up @@ -33,18 +33,19 @@ const requestlogging = {

const schemaWithMiddleware = applyMiddleware(schema, ...middlewares);

const context = ({ req }) => {
const context = ({ req }) => {
const token = req.headers.authorization;
if (token) {
if (token) {
try {
const { displayname, email, authoruid, languages, region } = jwt.verify(token, process.env.JWT_SECRET);
return { displayname, email, authoruid, languages, region };
const userAuthData = jwt.verify(token, process.env.JWT_SECRET);
userAuthData.isAuthenticated = true;
return userAuthData;
} catch (e) {
console.log('exception', e);
throw Error('Some error happens.');
console.log('exception', e.message);
return { isAuthenticated: false };
}
}
return {};
return { isAuthenticated: false };
}

const server = new ApolloServer({
Expand Down Expand Up @@ -106,6 +107,6 @@ app.listen(PORT, '0.0.0.0', err => {
console.error(err);
process.exit(0);
}

console.log(`Running server at http://localhost:${PORT} in ${NODE_ENV}`);
});
16 changes: 10 additions & 6 deletions src/mails/sendemail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import _ from 'lodash';
import path from 'path';
import SendMail from '../utils/sendemail';

export default async ({ to, subject, templatepath, maildata }) => {
const filepath = path.resolve(__dirname, templatepath);
export default async ({ to, subject, templatepath, maildata }) => {
if (process.env.NODE_ENV === 'development') {
console.log(`Verification link=> ${maildata.url}`);
return;
}

fs.readFile(filepath, { encoding: 'UTF-8' }, (err, templatedata) => {
const filepath = path.resolve(__dirname, templatepath);
fs.readFile(filepath, { encoding: 'UTF-8' }, (err, templatedata) => {
if (!err) {
const compiledTempate = _.template(templatedata);
const html = compiledTempate(maildata);
SendMail({to, subject, html});
SendMail({ to, subject, html });
}
else {
else {
console.log(`[ERROR] reading templatepath ${templatepath} | Error: ${err}`);
}
})

}

0 comments on commit 76d35b8

Please sign in to comment.