forked from HabitRPG/habitica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
76 lines (66 loc) · 3.11 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Load nconf and define default configuration values if config.json or ENV vars are not found
var conf = require('nconf');
conf.argv().env().file({ file: __dirname + "/config.json" }).defaults({
'PORT': 3000,
'IP': '0.0.0.0',
'BASE_URL': 'http://localhost',
'NODE_ENV': 'development'
});
// Override normal ENV values with nconf ENV values (ENV values are used the same way without nconf)
process.env.IP = conf.get("IP");
process.env.PORT = conf.get("PORT");
process.env.BASE_URL = conf.get("BASE_URL");
process.env.FACEBOOK_KEY = conf.get("FACEBOOK_KEY");
process.env.FACEBOOK_SECRET = conf.get("FACEBOOK_SECRET");
process.env.NODE_DB_URI = conf.get("NODE_DB_URI");
process.env.NODE_ENV = conf.get("NODE_ENV");
process.env.SESSION_SECRET = conf.get("SESSION_SECRET");
process.env.SMTP_USER = conf.get("SMTP_USER");
process.env.SMTP_PASS = conf.get("SMTP_PASS");
process.env.SMTP_SERVICE = conf.get("SMTP_SERVICE");
process.env.STRIPE_API_KEY = conf.get("STRIPE_API_KEY");
process.env.STRIPE_PUB_KEY = conf.get("STRIPE_PUB_KEY");
/*var agent;
if (process.env.NODE_ENV === 'development') {
// Follow these instructions for profiling / debugging leaks
// * https://developers.google.com/chrome-developer-tools/docs/heap-profiling
// * https://developers.google.com/chrome-developer-tools/docs/memory-analysis-101
agent = require('webkit-devtools-agent');
console.log("To debug memory leaks:" +
"\n\t(1) Run `kill -SIGUSR2 " + process.pid + "`" +
"\n\t(2) open http://c4milo.github.com/node-webkit-agent/21.0.1180.57/inspector.html?host=localhost:1337&page=0");
}*/
process.on('uncaughtException', function (error) {
function sendEmail(mailData) {
var 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
var smtpTransport = nodemailer.createTransport("SMTP",{
service: process.env.SMTP_SERVICE,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
});
// 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
});
}
sendEmail({
from: "HabitRPG <admin@habitrpg.com>",
to: "tylerrenelle@gmail.com",
subject: "HabitRPG Error",
text: error.stack
});
console.log(error.stack);
});
require('coffee-script') // remove intermediate compilation requirement
require('./src/server').listen(process.env.PORT || 3000, process.env.IP || '0.0.0.0');
// Note: removed "up" module, which is default for development (but interferes with and production + PaaS)
// Restore to 5310bb0 if I want it back (see https://github.com/codeparty/derby/issues/165#issuecomment-10405693)