better error handling
This commit is contained in:
@@ -12,11 +12,19 @@ app.listen(process.env.PORT, () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
let db
|
let db
|
||||||
|
async function connectToMongo() {
|
||||||
|
try {
|
||||||
const mongoUrl = `mongodb://${process.env.MONGO_SERVER}:27017`
|
const mongoUrl = `mongodb://${process.env.MONGO_SERVER}:27017`
|
||||||
MongoClient.connect(mongoUrl, { useNewUrlParser: true }).then(client => {
|
const client = await MongoClient.connect(mongoUrl, { useNewUrlParser: true })
|
||||||
db = client.db(process.env.MONGO_DB)
|
db = client.db(process.env.MONGO_DB)
|
||||||
console.log('Connected succesfully to server')
|
console.log('Connected succesfully to server')
|
||||||
}).catch(err => console.log(err))
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
setTimeout(connectToMongo, 5000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connectToMongo()
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.header('Access-Control-Allow-Origin', '*')
|
res.header('Access-Control-Allow-Origin', '*')
|
||||||
|
|||||||
Reference in New Issue
Block a user