Skip to content

Update app.js #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: starter-no-infra
Choose a base branch
from
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