diff --git a/config.json.example b/config.json.example index cc40d79701..c1cc52ad11 100644 --- a/config.json.example +++ b/config.json.example @@ -7,6 +7,7 @@ "NODE_DB_URI":"mongodb://localhost/habitrpg", "NODE_ENV":"development", "SESSION_SECRET":"YOUR SECRET HERE", + "ADMIN_EMAIL": "you@yours.com", "SMTP_USER":"user@domain.com", "SMTP_PASS":"password", "SMTP_SERVICE":"Gmail", diff --git a/src/errors.js b/src/errors.js deleted file mode 100644 index eff5f899e1..0000000000 --- a/src/errors.js +++ /dev/null @@ -1,39 +0,0 @@ -var nconf = require('nconf'); - -process.on("uncaughtException", function(error) { - var sendEmail; - sendEmail = function(mailData) { - var nodemailer, smtpTransport; - nodemailer = require("derby-auth/node_modules/nodemailer"); - /* create reusable transport method (opens pool of SMTP connections)*/ - - /* TODO derby-auth isn't currently configurable here, if you need customizations please send pull request*/ - - smtpTransport = nodemailer.createTransport("SMTP", { - service: nconf.get('SMTP_SERVICE'), - auth: { - user: nconf.get('SMTP_USER'), - pass: nconf.get('SMTP_PASS') - } - }); - /* send mail with defined transport object*/ - - return smtpTransport.sendMail(mailData, function(error, response) { - if (error) { - console.log(error); - } else { - console.log("Message sent: " + response.message); - } - /* shut down the connection pool, no more messages*/ - - return smtpTransport.close(); - }); - }; - sendEmail({ - from: "HabitRPG ", - to: "tylerrenelle@gmail.com", - subject: "HabitRPG Error", - text: error.stack - }); - return console.log(error.stack); -}); \ No newline at end of file diff --git a/src/server.js b/src/server.js index 7db81884d0..c38e877895 100644 --- a/src/server.js +++ b/src/server.js @@ -5,13 +5,23 @@ var http = require("http"); var path = require("path"); var app = express(); var nconf = require('nconf'); +var utils = require('./utils'); var middleware = require('./middleware'); var server; var TWO_WEEKS = 1000 * 60 * 60 * 24 * 14; // ------------ Setup configurations ------------ require('./config'); -require('./errors'); +process.on("uncaughtException", function(error) { + // when we hit an error, send it to admin as an email. If no ADMIN_EMAIL is present, just send it to yourself (SMTP_USER) + utils.sendEmail({ + from: "HabitRPG <" + nconf.get('SMTP_USER') + ">", + to: nconf.get('ADMIN_EMAIL') || nconf.get('SMTP_USER'), + subject: "HabitRPG Error", + text: error.stack + }); + console.error(error.stack); +}); // ------------ MongoDB Configuration ------------ mongoose = require('mongoose');