habitica/server.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2013-01-17 06:59:17 +00:00
/*process.on('uncaughtException', function(exception) {
2013-01-17 04:54:21 +00:00
notifyAdmin(exception)
console.error(exception)
2013-01-14 23:47:31 +00:00
});
2013-01-17 04:54:21 +00:00
require('coffee-script') // remove intermediate compilation requirement
2013-01-17 06:59:17 +00:00
require('./src/server').listen(process.env.PORT || 3000);*/
2013-01-17 04:54:21 +00:00
2013-01-17 06:59:17 +00:00
var forever = require('forever-monitor');
var child = new (forever.Monitor)('forever.js');
2013-01-17 04:54:21 +00:00
// FIXME on('error') and on('stderr') aren't working
2013-01-17 06:59:17 +00:00
child.on('restart', function(){
notifyAdmin('Server has restarted.')
2013-01-17 04:54:21 +00:00
});
2013-01-17 06:59:17 +00:00
child.on('exit', function() {
var err = 'server.js has exited after 10 restarts';
console.log(err);
notifyAdmin(err);
2013-01-17 04:54:21 +00:00
});
2013-01-17 06:59:17 +00:00
child.start();
2013-01-14 22:56:42 +00:00
function notifyAdmin(err){
var nodemailer = require("derby-auth/node_modules/nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP",{
service: process.env.SMTP_SERVICE || 'Gmail',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
});
var mailData = {
from: "HabitRPG <admin@habitrpg.com>",
to: 'tylerrenelle@gmail.com',
subject: "HabitRPG Error",
text: err
}
// send mail with defined transport object
smtpTransport.sendMail(mailData, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
smtpTransport.close(); // shut down the connection pool, no more messages
});
2013-01-17 04:54:21 +00:00
}