Add SMTP status check
This commit is contained in:
parent
a197ae9cc6
commit
5413c7dddf
@ -4,6 +4,8 @@ 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 accountsRoute = require('./routes/accountRoute');
|
const accountsRoute = require('./routes/accountRoute');
|
||||||
const meetingsRoute = require('./routes/meetingRoute');
|
const meetingsRoute = require('./routes/meetingRoute');
|
||||||
const participantsRoute = require('./routes/participantRoute');
|
const participantsRoute = require('./routes/participantRoute');
|
||||||
@ -34,10 +36,13 @@ 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);
|
||||||
|
|
||||||
server.get("/", (req, res) => {
|
const smtpMessage = smtpStatus();
|
||||||
|
|
||||||
|
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}`,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,12 +7,13 @@ module.exports = {
|
|||||||
dbURL: process.env.DATABASE_URL,
|
dbURL: process.env.DATABASE_URL,
|
||||||
// JWT
|
// JWT
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
saltingRounds: process.env.SALTING_ROUNDS || 10,
|
saltingRounds: 10,
|
||||||
// NODEMAILER
|
// NODEMAILER
|
||||||
smtpHost: process.env.SMTP_HOST,
|
smtpHost: process.env.SMTP_HOST,
|
||||||
smtpPort: process.env.SMTP_PORT,
|
smtpPort: process.env.SMTP_PORT,
|
||||||
smtpUsername: process.env.SMTP_USERNAME,
|
smtpUsername: process.env.SMTP_USERNAME,
|
||||||
smtpPassword: process.env.SMTP_PASSWORD,
|
smtpPassword: process.env.SMTP_PASSWORD,
|
||||||
smtpSecure: process.env.SMTP_SECURE || true, // use TLS
|
smtpRequireTLS: true, // True to force use of StartTLS
|
||||||
smtpPool: process.env.SMTP_POOL|| true, // Pool connections to server
|
smtpSecure: false, // False to force use of StartTLS
|
||||||
|
smtpPool: true, // Pool connections to server
|
||||||
};
|
};
|
||||||
|
15
helpers/smtpStatus.js
Normal file
15
helpers/smtpStatus.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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;
|
@ -6,15 +6,20 @@ const {
|
|||||||
smtpPort,
|
smtpPort,
|
||||||
smtpUsername,
|
smtpUsername,
|
||||||
smtpPassword,
|
smtpPassword,
|
||||||
|
smtpSecure,
|
||||||
|
smtpRequireTLS,
|
||||||
} = require('../config/config');
|
} = require('../config/config');
|
||||||
|
|
||||||
nodemailer.createTransport({
|
const smtpTransporter = nodemailer.createTransport({
|
||||||
pool: smtpPool,
|
pool: smtpPool,
|
||||||
host: smtpHost,
|
host: smtpHost,
|
||||||
port: smtpPort,
|
port: smtpPort,
|
||||||
|
requireTLS: smtpRequireTLS,
|
||||||
secure: smtpSecure,
|
secure: smtpSecure,
|
||||||
auth: {
|
auth: {
|
||||||
user: smtpUsername,
|
user: smtpUsername,
|
||||||
pass: smtpPassword,
|
pass: smtpPassword,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.exports = smtpTransporter;
|
||||||
|
Loading…
Reference in New Issue
Block a user