2018-04-09 20:22:41 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
2018-04-09 20:22:41 +00:00
|
|
|
var fs = require('fs')
|
|
|
|
var https = require('https')
|
2016-05-20 21:11:37 +00:00
|
|
|
|
2017-10-19 00:27:07 +00:00
|
|
|
require('dotenv').config({path: './.env'});
|
|
|
|
|
2017-10-19 00:18:18 +00:00
|
|
|
if(!process.env.NODE_ENV){
|
|
|
|
process.env.NODE_ENV = 'development';
|
|
|
|
}
|
|
|
|
|
2018-04-09 20:22:41 +00:00
|
|
|
var pkey = fs.readFileSync('/etc/letsencrypt/live/register.earlybird.camp/privkey.pem')
|
|
|
|
var cert = fs.readFileSync('/etc/letsencrypt/live/register.earlybird.camp/fullchain.pem')
|
|
|
|
|
2016-05-20 21:11:37 +00:00
|
|
|
|
2016-11-09 18:02:12 +00:00
|
|
|
require('events').EventEmitter.prototype._maxListeners = 0;
|
|
|
|
|
2017-04-23 02:23:23 +00:00
|
|
|
var config = require('./config/config'),
|
2015-06-29 22:51:29 +00:00
|
|
|
mongoose = require('mongoose'),
|
2017-11-06 21:44:29 +00:00
|
|
|
chalk = require('chalk'),
|
|
|
|
nodemailer = require('nodemailer');
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Main application entry file.
|
|
|
|
* Please note that the order of loading is important.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Bootstrap db connection
|
2016-10-24 07:13:38 +00:00
|
|
|
var db = mongoose.connect(config.db.uri, config.db.options, function (err) {
|
2015-06-29 22:51:29 +00:00
|
|
|
if (err) {
|
|
|
|
console.error(chalk.red('Could not connect to MongoDB!'));
|
|
|
|
console.log(chalk.red(err));
|
|
|
|
}
|
|
|
|
});
|
2016-10-24 07:13:38 +00:00
|
|
|
mongoose.connection.on('error', function (err) {
|
2015-06-29 22:51:29 +00:00
|
|
|
console.error(chalk.red('MongoDB connection error: ' + err));
|
|
|
|
process.exit(-1);
|
2015-08-11 20:32:27 +00:00
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2017-11-06 21:44:29 +00:00
|
|
|
const smtpTransport = nodemailer.createTransport(config.mailer.options);
|
2018-04-09 20:22:41 +00:00
|
|
|
console.log("GOT PAST MONGOOSE")
|
2017-11-06 21:44:29 +00:00
|
|
|
// verify connection configuration on startup
|
|
|
|
smtpTransport.verify(function(error, success) {
|
|
|
|
if (error) {
|
|
|
|
console.error(chalk.red('Your mail configuration is incorrect: ' + error));
|
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// Init the express application
|
|
|
|
var app = require('./config/express')(db);
|
|
|
|
|
2017-04-03 20:28:24 +00:00
|
|
|
//Create admin account
|
|
|
|
if (process.env.CREATE_ADMIN_ACCOUNT === 'TRUE') {
|
|
|
|
var create_admin = require('./scripts/create_admin');
|
|
|
|
|
|
|
|
create_admin.run(app, db, function(err){
|
|
|
|
if(err){
|
|
|
|
console.error(chalk.red('Could not create Admin Account: ' + err));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// Bootstrap passport config
|
|
|
|
require('./config/passport')();
|
2018-04-09 20:22:41 +00:00
|
|
|
console.log("Got past passport!")
|
2015-06-29 22:51:29 +00:00
|
|
|
// Start the app by listening on <port>
|
2018-04-09 20:22:41 +00:00
|
|
|
app.listen(80, () => console.log("Listening"));
|
|
|
|
console.log("Got past Listen1")
|
|
|
|
|
|
|
|
//https.createServer({key: pkey, cert: cert}, app).listen(config.port, () => {
|
|
|
|
// console.log('Listening on 443')
|
|
|
|
//})
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2018-04-09 20:22:41 +00:00
|
|
|
console.log("GOT PAST LISTEN");
|
2015-06-29 22:51:29 +00:00
|
|
|
// Expose app
|
|
|
|
exports = module.exports = app;
|
|
|
|
|
|
|
|
// Logging initialization
|
|
|
|
console.log('--');
|
|
|
|
console.log(chalk.green('Environment:\t\t\t' + process.env.NODE_ENV));
|
|
|
|
console.log(chalk.green('Port:\t\t\t\t' + config.port));
|
|
|
|
console.log(chalk.green('Database:\t\t\t' + config.db.uri));
|
|
|
|
if (process.env.NODE_ENV === 'secure') {
|
|
|
|
console.log(chalk.green('HTTPs:\t\t\t\ton'));
|
|
|
|
}
|
|
|
|
console.log('--');
|
2016-05-20 20:28:27 +00:00
|
|
|
|
|
|
|
process.on('uncaughtException', function (err) {
|
2016-06-04 07:00:31 +00:00
|
|
|
console.error((new Date()).toUTCString() + ' uncaughtException:', err.message);
|
2016-05-20 20:28:27 +00:00
|
|
|
console.error(err.stack);
|
2016-05-20 21:11:37 +00:00
|
|
|
process.exit(1);
|
2017-10-19 00:18:18 +00:00
|
|
|
});
|