fix: sanitize MONGODB_URI scheme validation in db-mongodb.js
This commit is contained in:
+10
-2
@@ -13,7 +13,14 @@ export function generateUUID() {
|
||||
});
|
||||
}
|
||||
|
||||
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017';
|
||||
function getMongoUri() {
|
||||
const envUri = (process.env.MONGODB_URI || '').trim();
|
||||
if (envUri.startsWith('mongodb://') || envUri.startsWith('mongodb+srv://')) {
|
||||
return envUri;
|
||||
}
|
||||
return 'mongodb://127.0.0.1:27017';
|
||||
}
|
||||
|
||||
const DB_NAME = process.env.DB_NAME || 'hospital';
|
||||
|
||||
let client;
|
||||
@@ -62,7 +69,8 @@ const memStore = {
|
||||
|
||||
export async function initDb() {
|
||||
try {
|
||||
client = new MongoClient(MONGODB_URI, {
|
||||
const uri = getMongoUri();
|
||||
client = new MongoClient(uri, {
|
||||
connectTimeoutMS: 5000,
|
||||
serverSelectionTimeoutMS: 5000
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user