Skip to content

Commit dce32ad

Browse files
authored
Merge pull request #1367 from CVEProject/dr_dev_env
Dealing with multiple connection types.
2 parents 0bac76a + 9d085c5 commit dce32ad

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ RATE_LIMIT_WINDOW_SECONDS=60
66
# The maximum number of connections allowed within the rate limiting window.
77
# This sets the threshold for how many requests can be made in the specified time frame.
88
RATE_LIMIT_MAX_CONNECTIONS=1000
9+
USEMONGO=true

.github/workflows/test-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
while ! $dockercompose logs cveawg | grep -q 'Serving on port'; do
2424
attempts=$(expr $attempts - 1)
2525
if [ $($dockercompose ps --status running -q | wc -l) -eq 2 ] && [ $attempts -gt 0 ]; then
26-
sleep 1
26+
sleep 10
2727
$dockercompose logs || true
2828
continue
2929
fi

src/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ app.use((req, res, next) => {
4848

4949
// Connect to MongoDB database
5050
const dbConnectionStr = dbUtils.getMongoConnectionString()
51-
mongoose.connect(dbConnectionStr, {
52-
authMechanism: 'SCRAM-SHA-1',
53-
tls: false
54-
})
51+
const dbConnectionOptions = dbUtils.getMongoConnectionOptions()
52+
53+
// First attempt: try connecting with authMechanism
54+
mongoose.connect(dbConnectionStr, dbConnectionOptions)
5555

56-
// database connection
5756
const db = mongoose.connection
5857

5958
db.on('error', () => {

src/utils/db.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const config = require('config')
2-
2+
const { booleanIsTrue } = require('./utils')
33
const logger = require('../middleware/logger')
44

55
/* constructs MongoDB connection string
@@ -30,6 +30,19 @@ function getMongoConnectionString () {
3030
return `mongodb://${dbLoginPrepend}${dbHost}:${dbPort}/${dbName}`
3131
}
3232

33+
function getMongoConnectionOptions () {
34+
if (process.env.USEMONGO !== undefined && booleanIsTrue(process.env.USEMONGO)) {
35+
return {
36+
tls: false
37+
}
38+
}
39+
return {
40+
authMechanism: 'SCRAM-SHA-1',
41+
tls: false
42+
}
43+
}
44+
3345
module.exports = {
34-
getMongoConnectionString
46+
getMongoConnectionString,
47+
getMongoConnectionOptions
3548
}

0 commit comments

Comments
 (0)