From d5e80d5ec7c55da2f5a5810ad545e7be42824036 Mon Sep 17 00:00:00 2001 From: Faizal Abdul Khader Date: Wed, 29 Sep 2021 15:44:39 -0500 Subject: [PATCH] changed mongoose connect #19 --- accounts/.env | 4 +++- accounts/server.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/accounts/.env b/accounts/.env index fa98313..c58a6f8 100644 --- a/accounts/.env +++ b/accounts/.env @@ -1,8 +1,10 @@ PORT=3400 MONGO_URL='mongodb://user:password@example-mongodb-svc.mongodb/admin' MONGODB_REPLICA_HOSTNAMES: example-mongodb-svc.mongodb.svc.cluster.local:27017 -MONGODB_DBNAME: example +MONGODB_DBNAME: admin MONGODB_USER: user MONGODB_PASSWORD: password MONGODB_AUTH_DBNAME: admin +MONGODB_REPLICA_SET: example-node-deployment +MONGODB_CA_PATH: '' BASE_PATH=0.0.0.0 diff --git a/accounts/server.js b/accounts/server.js index 39abf49..0b05609 100644 --- a/accounts/server.js +++ b/accounts/server.js @@ -7,7 +7,16 @@ require('dotenv').config({silent: true, path: `${__dirname}/.env`}); var server = require('./app'); var port = 3400; -console.log(`Running on ${process.env.BASE_PATH}:${port}, connecting to ${process.env.MONGO_URL}`) +// environment variables for mongodb connection +const MONGODB_REPLICA_HOSTNAMES = process.env.MONGODB_REPLICA_HOSTNAMES +const MONGODB_REPLICA_SET = process.env.MONGODB_REPLICA_SET +const MONGODB_DBNAME = process.env.MONGODB_DBNAME +const MONGODB_AUTH_DBNAME = process.env.MONGODB_AUTH_DBNAME || MONGODB_DBNAME +const MONGODB_CA_PATH = process.env.MONGODB_CA_PATH +const MONGODB_USER = process.env.MONGODB_USER +const MONGODB_PASSWORD = process.env.MONGODB_PASSWORD + +console.log(`Running on ${process.env.BASE_PATH}:${port}, connecting to ${process.env.MONGO_URL} and mongo host `+MONGODB_REPLICA_HOSTNAMES) // connection to mongodb mongoose @@ -15,8 +24,10 @@ mongoose user: MONGODB_USER, pass: MONGODB_PASSWORD, dbName: MONGODB_DBNAME, + replicaSet: MONGODB_REPLICA_SET, authSource: MONGODB_AUTH_DBNAME, tls: false, + tlsCAFile: MONGODB_CA_PATH, useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true})