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
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
30bf9beea5
commit
6024a1fe7f
@ -7,6 +7,7 @@
|
|||||||
"driver": "sqlite",
|
"driver": "sqlite",
|
||||||
"connection_string": "data/overseer.db"
|
"connection_string": "data/overseer.db"
|
||||||
},
|
},
|
||||||
|
"use_redis": false,
|
||||||
"redis": {
|
"redis": {
|
||||||
"host": "192.168.1.10",
|
"host": "192.168.1.10",
|
||||||
"port": 6379,
|
"port": 6379,
|
||||||
|
21
index.js
21
index.js
@ -1,7 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const session = require('express-session');
|
const session = require('express-session');
|
||||||
const RedisStore = require('connect-redis')(session);
|
const RedisStore = require('connect-redis')(session);
|
||||||
// const flash = require('express-flasher');
|
// const flash = require('@bitgoblin/express-flasher');
|
||||||
|
|
||||||
// instantiate new express.js app
|
// instantiate new express.js app
|
||||||
const app = express();
|
const app = express();
|
||||||
@ -15,18 +15,27 @@ const config = require('config');
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// initialize Redis store for session data
|
if (config.get('use_redis')) {
|
||||||
const redisClient = require('./src/redis');
|
// initialize Redis store for session data
|
||||||
|
const redisClient = require('./src/redis');
|
||||||
|
|
||||||
// initialize express.js session w/ Redis datastore
|
// initialize express.js session w/ Redis datastore
|
||||||
app.use(session({
|
app.use(session({
|
||||||
store: new RedisStore({
|
store: new RedisStore({
|
||||||
client: redisClient,
|
client: redisClient,
|
||||||
}), // use Redis datastore
|
}), // use Redis datastore
|
||||||
resave: false, // don't save session if unmodified
|
resave: false, // don't save session if unmodified
|
||||||
saveUninitialized: false, // don't create session until something stored
|
saveUninitialized: false, // don't create session until something stored
|
||||||
secret: 'lord of the rings',
|
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
|
// setup flash messaging
|
||||||
// app.use(flash.flash());
|
// app.use(flash.flash());
|
||||||
|
@ -4,11 +4,11 @@ exports.default = function() {
|
|||||||
let redisUrl = 'redis://';
|
let redisUrl = 'redis://';
|
||||||
|
|
||||||
// add the redis username if defined
|
// add the redis username if defined
|
||||||
if (typeof redisConfig.get('username') !== 'undefined') {
|
if (redisConfig.has('username')) {
|
||||||
redisUrl += redisConfig.get('username');
|
redisUrl += redisConfig.get('username');
|
||||||
}
|
}
|
||||||
// add the user password if defined
|
// add the user password if defined
|
||||||
if (typeof redisConfig.get('password') !== 'undefined') {
|
if (redisConfig.has('password')) {
|
||||||
redisUrl += ':' + redisConfig.get('password') + '@';
|
redisUrl += ':' + redisConfig.get('password') + '@';
|
||||||
}
|
}
|
||||||
// add redis host URL
|
// add redis host URL
|
||||||
@ -16,7 +16,7 @@ exports.default = function() {
|
|||||||
// add redis host port
|
// add redis host port
|
||||||
redisUrl += ':' + redisConfig.get('port');
|
redisUrl += ':' + redisConfig.get('port');
|
||||||
// add redis database number if defined
|
// add redis database number if defined
|
||||||
if (typeof redisConfig.get('number') !== 'undefined') {
|
if (redisConfig.has('number')) {
|
||||||
redisUrl += redisConfig.get('number');
|
redisUrl += redisConfig.get('number');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user