Skip to content

Commit

Permalink
feat: optimize how we get dburl
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapaprasanna committed Aug 5, 2024
1 parent c32725f commit 1f89992
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions deploy/docker/fs/opt/appsmith/utils/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ function start(apps) {
console.log("Started " + appsStr);
}


function getDburl() {
let dbUrl = '';
try {
let env_array = fs.readFileSync(Constants.ENV_PATH, 'utf8').toString().split("\n");
for(i in env_array) {
if (env_array[i].startsWith("APPSMITH_MONGODB_URI") || env_array[i].startsWith("APPSMITH_DB_URL")) {
var dbUrl = env_array[i].toString().split("=")[1];
}
for (let i in env_array) {
if (env_array[i].startsWith("APPSMITH_MONGODB_URI") || env_array[i].startsWith("APPSMITH_DB_URL")) {
dbUrl = env_array[i].toString().split("=")[1];
break; // Break early when the desired line is found
}
}
} catch (err) {
console.error(err);
console.error("Error reading the environment file:", err);
}
let dbEnvUrl = process.env.APPSMITH_DB_URL || process.env.APPSMITH_MONGO_DB_URI;
if (dbEnvUrl != "undefined"){
var dbUrl = dbEnvUrl;
if (dbEnvUrl && dbEnvUrl !== "undefined") {
dbUrl = dbEnvUrl;
}
return dbUrl;
}
Expand Down Expand Up @@ -195,4 +196,4 @@ module.exports = {
execCommandSilent,
getDatabaseNameFromMongoURI,
getDburl
};
};

0 comments on commit 1f89992

Please sign in to comment.