Skip to content

Commit

Permalink
Merge pull request #112 from draadnl/feature/mongodb-authentication
Browse files Browse the repository at this point in the history
Allow MongoDB credentials to be set
  • Loading branch information
rudivanhierden authored Aug 25, 2022
2 parents c1e2b1f + 12b32db commit d4b2935
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,24 @@ const sessionStore = new MySQLStore({
*/


const mongoCredentials = {
host: process.env.MONGO_DB_HOST || 'localhost',
port: process.env.MONGO_DB_PORT || 27017,
function getMongoDbConnectionString () {
// Allow the connection string builder to be overridden by an environment variable
if (process.env.MONGO_DB_CONNECTION_STRING) {
return process.env.MONGO_DB_CONNECTION_STRING;
}

const host = process.env.MONGO_DB_HOST || 'localhost';
const port = process.env.MONGO_DB_PORT || 27017;
const user = process.env.MONGO_DB_USER || '';
const password = process.env.MONGO_DB_PASSWORD || '';
const authSource = process.env.MONGO_DB_AUTHSOURCE || '';

const useAuth = user && password;

return `mongodb://${useAuth ? `${user}:${password}@` : ''}${host}:${port}/sessions${authSource ? `?authSource=${authSource}` : ''}`;
}

const url = 'mongodb://'+ mongoCredentials.host +':'+mongoCredentials.port+'/sessions';
const url = getMongoDbConnectionString();

const sessionStore = new MongoStore({
url: url,
Expand Down

0 comments on commit d4b2935

Please sign in to comment.