Added option to enable/disable redis session store; fixed the checks for username, password, and database number when setting up the Redis connection
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-11-23 22:17:36 -05:00
parent 30bf9beea5
commit 6024a1fe7f
3 changed files with 25 additions and 15 deletions

View File

@ -7,6 +7,7 @@
"driver": "sqlite",
"connection_string": "data/overseer.db"
},
"use_redis": false,
"redis": {
"host": "192.168.1.10",
"port": 6379,

View File

@ -1,7 +1,7 @@
const express = require('express');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
// const flash = require('express-flasher');
// const flash = require('@bitgoblin/express-flasher');
// instantiate new express.js app
const app = express();
@ -15,18 +15,27 @@ const config = require('config');
});
})();
// initialize Redis store for session data
const redisClient = require('./src/redis');
if (config.get('use_redis')) {
// initialize Redis store for session data
const redisClient = require('./src/redis');
// initialize express.js session w/ Redis datastore
app.use(session({
store: new RedisStore({
client: redisClient,
}), // use Redis datastore
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret: 'lord of the rings',
}));
// initialize express.js session w/ Redis datastore
app.use(session({
store: new RedisStore({
client: redisClient,
}), // use Redis datastore
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret: 'lord of the rings',
}));
} else {
// initialize express.js session w/ Redis datastore
app.use(session({
resave: false, // don't save session if unmodified
saveUninitialized: false, // don't create session until something stored
secret: 'lord of the rings',
}));
}
// setup flash messaging
// app.use(flash.flash());

View File

@ -4,11 +4,11 @@ exports.default = function() {
let redisUrl = 'redis://';
// add the redis username if defined
if (typeof redisConfig.get('username') !== 'undefined') {
if (redisConfig.has('username')) {
redisUrl += redisConfig.get('username');
}
// add the user password if defined
if (typeof redisConfig.get('password') !== 'undefined') {
if (redisConfig.has('password')) {
redisUrl += ':' + redisConfig.get('password') + '@';
}
// add redis host URL
@ -16,7 +16,7 @@ exports.default = function() {
// add redis host port
redisUrl += ':' + redisConfig.get('port');
// add redis database number if defined
if (typeof redisConfig.get('number') !== 'undefined') {
if (redisConfig.has('number')) {
redisUrl += redisConfig.get('number');
}