39 lines
852 B
JavaScript
39 lines
852 B
JavaScript
'use strict'
|
|
|
|
const chalk = require('chalk')
|
|
const session = require('express-session')
|
|
|
|
let redisStore
|
|
|
|
const config = {
|
|
secret:
|
|
'asdfpoi7u987777777777777777777sdkafjxxjasdhfhsadfhashdfh`1111111khjjashdfkasjhdflGGGGGGGGGGaaa^^^^^^^^^^yaghsdfqw3u7679`',
|
|
resave: false,
|
|
saveUninitialized: true,
|
|
}
|
|
|
|
const redisConfig = {
|
|
host: 'localhost',
|
|
port: 6379,
|
|
}
|
|
|
|
if (ENV === 'production') {
|
|
const RedisStore = require('connect-redis')(require('express-session'))
|
|
|
|
redisStore = new RedisStore(redisConfig)
|
|
|
|
redisStore.on('connect', () => {
|
|
console.info(`[${chalk.cyan('INIT')}] Redis connected succcessfully`)
|
|
})
|
|
|
|
redisStore.on('disconnect', () => {
|
|
throw new Error('Unable to connect to redis. Has it been started?')
|
|
})
|
|
|
|
config.store = redisStore
|
|
} else {
|
|
config.store = new session.MemoryStore()
|
|
}
|
|
|
|
module.exports = config
|