mirror of
https://github.com/docker/awesome-compose.git
synced 2025-04-25 18:28:07 +02:00
react-express-mongodb: rename server to backend
The goal here is to keep the same structure than the other examples. Also, considering that it has a "frontend" folder, the equivalent for the server should be "backend". Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
parent
e29f0d1c54
commit
be8875c9b6
16 changed files with 8 additions and 8 deletions
30
react-express-mongodb/backend/db/index.js
vendored
Normal file
30
react-express-mongodb/backend/db/index.js
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Created by Syed Afzal
|
||||
*/
|
||||
const mongoose = require('mongoose');
|
||||
const {log} = require('../utils/helpers/logger');
|
||||
|
||||
exports.connect = (app) => {
|
||||
const options = {
|
||||
useNewUrlParser: true,
|
||||
autoIndex: false, // Don't build indexes
|
||||
reconnectTries: 30, // Retry up to 30 times
|
||||
reconnectInterval: 500, // Reconnect every 500ms
|
||||
poolSize: 10, // Maintain up to 10 socket connections
|
||||
// If not connected, return errors immediately rather than waiting for reconnect
|
||||
bufferMaxEntries: 0
|
||||
}
|
||||
|
||||
const connectWithRetry = () => {
|
||||
mongoose.Promise = global.Promise;
|
||||
console.log('MongoDB connection with retry')
|
||||
mongoose.connect(process.env.MONGODB_URI, options).then(()=>{
|
||||
console.log('MongoDB is connected');
|
||||
app.emit('ready');
|
||||
}).catch(err=>{
|
||||
console.log('MongoDB connection unsuccessful, retry after 2 seconds.')
|
||||
setTimeout(connectWithRetry, 2000)
|
||||
})
|
||||
}
|
||||
connectWithRetry();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue