Don't require the mailconfig, but log out in the console that it wont be enabled.

This commit is contained in:
Kasper Rynning-Tønnesen
2017-11-10 16:45:59 +01:00
parent 4e58c0a77f
commit adf72fa296
2 changed files with 60 additions and 52 deletions

View File

@@ -1,3 +1,9 @@
/**
*
* Have a look at nodemailer's config on how to set this up https://nodemailer.com/about/
*
*/
var mail_config = { var mail_config = {
port: 587, port: 587,
host: 'smtp.example.com', host: 'smtp.example.com',

View File

@@ -1,15 +1,6 @@
var express = require('express'); var express = require('express');
var router = express.Router(); var router = express.Router();
var path = require('path'); var path = require('path');
var nodemailer = require('nodemailer');
try {
var mailconfig = require(path.join(__dirname, '../config/mailconfig.js'));
} catch(e) {
console.log("Error - missing file");
console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js.");
process.exit();
}
router.use(function(req, res, next) { router.use(function(req, res, next) {
next(); // make sure we go to the next routes and don't stop here next(); // make sure we go to the next routes and don't stop here
@@ -42,8 +33,7 @@ router.route('/api/list/:channel_name').get(function(req, res) {
router.route('/api/conf/:channel_name').get(function(req, res) { router.route('/api/conf/:channel_name').get(function(req, res) {
var channel_name = req.params.channel_name; var channel_name = req.params.channel_name;
db.collection(channel_name).find({views: {$exists: true}}, db.collection(channel_name).find({views: {$exists: true}}, {
{
addsongs: 1, addsongs: 1,
adminpass: 1, adminpass: 1,
allvideos: 1, allvideos: 1,
@@ -89,6 +79,9 @@ router.route('/api/conf/:channel_name').get(function(req, res) {
}); });
}); });
var nodemailer = require('nodemailer');
try {
var mailconfig = require(path.join(__dirname, '../config/mailconfig.js'));
router.route('/api/mail').post(function(req, res) { router.route('/api/mail').post(function(req, res) {
let transporter = nodemailer.createTransport(mailconfig); let transporter = nodemailer.createTransport(mailconfig);
@@ -119,5 +112,14 @@ router.route('/api/conf/:channel_name').get(function(req, res) {
} }
}); });
}); });
} catch(e) {
console.log("Mail not setup and wont work");
console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js.");
router.route('/api/mail').post(function(req, res) {
console.log("Someone tried to send a mail, but the mailsystem hasn't been enabled..")
res.send("failed");
return;
});
}
module.exports = router; module.exports = router;