Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const compileOptions = {
escape: /{{([^{][\s\S]+?[^}])}}/g,
interpolate: /{{{([\s\S]+?)}}}/g
}
const isProd = process.env.NODE_ENV === 'production'
process.noDeprecation = true
const app = express()
let cache
if (config.server.useOutputCache) {
cache = new TagCache({
redis: config.redis,
defaultTimeout: config.server.outputCacheDefaultTtl // Expire records after a day (even if they weren't invalidated)
})
console.log('Redis cache set', config.redis)
}
const templatesCache = {}
let renderer
for (const tplName of Object.keys(config.ssr.templates)) {
const fileName = resolve(config.ssr.templates[tplName])
if (fs.existsSync(fileName)) {
const template = fs.readFileSync(fileName, 'utf-8')
templatesCache[tplName] = compile(template, compileOptions)
}
}
if (isProd) {
// In production: create server renderer using server bundle and index HTML
// template from real fs.
// The server bundle is generated by vue-ssr-webpack-plugin.
const clientManifest = require(resolve('dist/vue-ssr-client-manifest.json'))
if (config.sockets) {
http.globalAgent.maxSockets = Math.floor(config.sockets / 2)
https.globalAgent.maxSockets = Math.floor(config.sockets / 2)
}
// Init Koop with things it needs like a log and Cache
koop.log = new koop.Logger(config)
koop.Cache = new koop.DataCache(koop)
// registers a DB modules
koop.Cache.db = pgcache.connect(config.db.conn, koop)
// Create the job queue for this worker process
// connects to the redis same redis
var jobs = kue.createQueue({
prefix: config.redis.prefix,
redis: {
port: config.redis.port,
host: config.redis.host
}
})
process.once('SIGINT', function (sig) {
jobs.active(function (err, ids) {
if (err) {
koop.log.error(util.inspect(err))
}
if (ids.length) {
ids.forEach(function (id) {
kue.Job.get(id, function (err, job) {
if (err) {
koop.log.error(util.inspect(err))
var bunyan = require('bunyan');
var restify_endpoints = require('restify-endpoints');
// Setup logger
var logger = bunyan.createLogger({
name: 'docker-index',
stream: process.stdout,
level: config.loglevel,
src: true,
serializers: {
req: bunyan.stdSerializers.req
}
});
// Setup Redis Connection
var redis = require('redis').createClient(config.redis.port, config.redis.host);
redis.on('error', function(err) {
logger.error({domain: 'redis', err: err, stack: err.stack});
});
// Setup Restify Endpoints
var endpoints = new restify_endpoints.EndpointManager({
endpointpath: __dirname + '/endpoints',
endpoint_args: [config, redis, logger]
});
// Create our Restify server
var server = restify.createServer({
name: 'docker-index',
version: '1.0.0'
});
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(require('morgan')('dev'));
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(require('cookie-parser')());
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
app.use(session({
store: new RedisStore(config.redis),
secret: config.session.secret,
cookie: {
maxAge: 60000 * 60 * 24 * 14
}
}));
app.use(function(req, res, next) {
res.locals.config = config;
res.locals.req = req;
next();
});
app.use('/public', express.static(path.join(__dirname, 'public')));
require('./routes')(app);
case '&':
case '?':
case '*':
throw new Error('Characters &, ? and * are invalid for param folding-char!');
}
// special handling of no* by optimist module needed
if (value['save']) value['nosave'] = false;
// now write back all values into config object to overwrite defaults with cli params
config.noSave = value['nosave'];
config.noLogData = (value['log-data']===false); // due to special negated param
config.ui.foldingChar = value['folding-char'];
config.redis.useScan = value['use-scan'];
config.redis.readOnly = value['read-only'];
config.redis.scanCount = value['scan-count'];
config.redis.rootPattern = value['root-pattern'];
config.redis.defaultLabel = value['redis-label'];
config.server.address = value['address'];
config.server.port = value['port'];
config.server.urlPrefix = value['url-prefix'];
config.server.trustProxy = value['trust-proxy'];
config.server.httpAuth.username = value['http-auth-username'];
config.server.httpAuth.password = value['http-auth-password'];
config.server.httpAuth.passwordHash = value['http-auth-password-hash'];
})
.argv;
const initRedisClient = function () {
let client, redisInfo
if (config.redis.url) {
redisInfo = new URL(config.redis.url)
client = redis.createClient(redisInfo.port, redisInfo.hostname)
} else {
client = redis.createClient(config.redis.port, 'localhost')
}
const closeRedisConnection = function (error, exitCode) {
if (error) {
logger.error(error)
}
client.quit()
client.on('end', function () {
logger.info('Disconnected from Redis')
})
}
'use strict';
const config = require('config');
const Redis = require('ioredis');
let connections = {};
Object.keys(config.redis).forEach((name) => {
connections[name] = new Redis(config.redis[name]);
});
module.exports = function getRedis(name) {
return connections[name];
};
var config = require('config');
var redis = require('redis').createClient(config.redis.port, config.redis.host);
var async = require('async');
async.series([
function(cb) {
redis.smembers('users', function(err, users) {
if (typeof(users) != "undefined") {
for (var i = 0; i < users.length; i++) {
redis.del('user:' + users[i]);
redis.srem('users', users[i]);
}
}
cb(null);
});
},
function(cb) {
const program = require('commander')
const config = require('config').redis
const kue = require('kue')
program
.command('dashboard')
.option('-p|--port ', 'port on which to run kue dashboard', 3000)
.option('-q|--prefix ', 'prefix', 'q')
.action((cmd) => {
kue.createQueue({
redis: config,
prefix: cmd.prefix
})
kue.app.listen(cmd.port)
});
program