Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var logfmt = require('logfmt');
var passport = require('passport');
var mongoose = require('mongoose');
var redis = require('redis');
var RedisStore = require('connect-redis')(session);
var busboy = require('connect-busboy');
mongoose.connect(process.env.MONGOHQ_URL || 'mongodb://localhost');
if (process.env.REDISTOGO_URL) {
// inside if statement
var rtg = require("url").parse(process.env.REDISTOGO_URL);
var redis = require("redis").createClient(rtg.port, rtg.hostname);
redis.auth(rtg.auth.split(":")[1]);
} else {
var redis = require("redis").createClient();
}
// redis.sadd('guests', 'g1');
var sessionStore = new RedisStore({ client: redis });
var app = express();
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.use('/static', express.static(__dirname + '/../static'));
app.use(cookieParser());
app.use(busboy());
function connect() {
if (client) return;
if (process.env.REDISTOGO_URL) {
var rtg = new URL(process.env.REDISTOGO_URL);
client = redis.createClient(rtg.port, rtg.hostname);
redis.auth(rtg.password);
} else {
client = redis.createClient();
}
client.on('error', function(err) {
console.log('redis error: ', err);
});
}
var scheduler = function (options) {
var mongo = require('mongodb')
, redis = require('redis')
, async = require('async')
, userBee = require('./user-bee')(options);
var mongoServer = new mongo.Server(options.mongodb.host, options.mongodb.port, options.mongodb.options);
var db = new mongo.Db('user_bee', mongoServer, {safe:false});
var laterRefs = new Array();
var redis = redis.createClient(options.redis.port, options.redis.host);
if (options.redis.hasOwnProperty('password')) {
redis.auth(options.redis.password);
}
/**
* Private functions
*/
var _processTrigger = function (trigger) {
db.collection('attributes', function (err, collection) {
if (err) {
console.error("Could not fetch attributes collection from mongodb: " + err);
return false;
}
//TODO: Exclude unsubscribed users
//Fetch users for whom this trigger has not been triggered yet
var queryCondition = ('query' in trigger) ? trigger.query : ('queryFunction' in trigger ? eval('(' + trigger.queryFunction + ')()') : {})