Add function to check SMTP status

This commit is contained in:
rui hildt 2020-08-29 18:14:39 +02:00
parent 6a378df5cf
commit 4579be1541
4 changed files with 18 additions and 18 deletions

View File

@ -4,7 +4,7 @@ const bodyParser = require('body-parser');
const cors = require('cors'); const cors = require('cors');
const helmet = require('helmet'); const helmet = require('helmet');
const smtpStatus = require('../helpers/smtpStatus'); const logSmtpStatus = require('../helpers/logSmtpStatus');
const accountsRoute = require('./routes/accountRoute'); const accountsRoute = require('./routes/accountRoute');
const meetingsRoute = require('./routes/meetingRoute'); const meetingsRoute = require('./routes/meetingRoute');
@ -36,13 +36,14 @@ server.use('/api/possible-dates', possibleDatesRoute);
server.use('/api/availability', availabilityRoute); server.use('/api/availability', availabilityRoute);
server.use('/api/auth', authRoute); server.use('/api/auth', authRoute);
const smtpMessage = smtpStatus(); // Uncomment to log SMTP status. If config is correct,
// the console will output:'SMTP is correctly configured.'
// logSmtpStatus();
server.get('/', (req, res) => { server.get('/', (req, res) => {
res.json({ res.json({
message: `Meeting Planner Backend API :)`, message: `Meeting Planner Backend API :)`,
documentation: `Check out: https://git.armada.digital/meeting-planner/backend`, documentation: `Check out: https://git.armada.digital/meeting-planner/backend`,
SMTP: `${smtpMessage}`,
}); });
}); });

14
helpers/logSmtpStatus.js Normal file
View File

@ -0,0 +1,14 @@
const transporter = require('./smtpConfig');
function logSmtpStatus() {
transporter.verify(function (error, success) {
if (error) {
console.log('SMTP is not working, check your configuration.');
return ``;
} else {
console.log('SMTP is correctly configured.');
}
});
}
module.exports = logSmtpStatus;

View File

@ -1,15 +0,0 @@
const smtpTransporter = require('./smtpTransporter');
function smtpStatus() {
smtpTransporter.verify(function (error, success) {
if (error) {
console.log(error);
return `SMTP is not working, check your configuration.`
} else {
console.log('Server is ready to take our messages');
return `SMTP is correctly configured.`
}
});
}
module.exports = smtpStatus;