Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ async function getApp() {

// Database
// Use AZURE_COSMOS_CONNECTIONSTRING if available, otherwise fall back to MONGODB_URI
const mongoUri = process.env.MONGODB_URI; // For App Service, change to process.env.AZURE_COSMOS_CONNECTIONSTRING || process.env.MONGODB_URI;

mongoose.connect(mongoUri).then(() => {
const mongoUri = process.env.AZURE_COSMOS_CONNECTIONSTRING || process.env.MONGODB_URI; // For App Service, change to process.env.AZURE_COSMOS_CONNECTIONSTRING || process.env.MONGODB_URI;

const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 30000, // Increase timeout duration
socketTimeoutMS: 45000, // Increase socket timeout
};

try {
// Wait for the database connection to succeed
await mongoose.connect(mongoUri, options);
console.log('Connected to database');
}).catch((err) => {
} catch (err) {
console.error('Error connecting to database:', err);
});
throw new Error('Database connection failed'); // Will stop app startup if failed
}


var app = express();

Expand Down