Apply Javascript styleguide

This commit is contained in:
Jonathan Cremin 2015-08-23 22:12:32 +01:00
parent 752ce964c8
commit 6e0f351093
30 changed files with 364 additions and 375 deletions

View file

@ -9,17 +9,20 @@ const redisUrl = process.env.REDIS_URL || process.env.REDISTOGO_URL || 'redis://
const connection = new Promise((resolve, reject) => {
debug('Connecting to Redis');
resolve(redis.connect(redisUrl));
const client = redis.connect(redisUrl);
client.on('error', reject);
resolve(client);
}).catch((err) => {
debug('Connection error: ' + err);
throw err;
});
const redisSession = new Promise((resolve, reject) => {
return connection.then((client) => {
client = koaRedis({client: client});
const sessionClient = koaRedis({client: client});
resolve(session({
key: 'hid',
store: client
store: sessionClient,
}));
}).catch((err) => {
debug('koa-redis error: ' + err);
@ -29,31 +32,29 @@ const redisSession = new Promise((resolve, reject) => {
const wrapped = new Promise((resolve, reject) => {
return connection.then((client) => {
client = coRedis(client);
client.on('error', (err) => {
debug('Client error: ' + err);
reject(err);
});
client.on('ready', () => {
const asyncClient = coRedis(client);
asyncClient.on('error', reject);
asyncClient.on('ready', () => {
debug('Successfully connected to Redis');
resolve(client);
resolve(asyncClient);
});
}).catch((err) => {
debug('co-redis error: ' + err);
reject(err);
throw err;
});
});
export function sessionStore() {
return function* (next) {
return function* sessionStoreMiddleware(next) {
const sess = yield redisSession;
yield sess.bind(this)(next);
}
};
}
export function middleware() {
return function* (next) {
return function* redisMiddleware(next) {
this.redis = yield wrapped;
yield next;
}
};
}