2022-04-04 20:15:43 -05:00
|
|
|
import mongoose from "mongoose";
|
|
|
|
|
2022-04-07 17:56:04 -05:00
|
|
|
export function needDatabase(req, res, next) {
|
|
|
|
if (checkDatabaseConnection()) {
|
2022-04-04 20:15:43 -05:00
|
|
|
res.status(500).send("Internal server error: Database connection faulty.");
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
2022-04-07 17:56:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function checkDatabaseConnection() {
|
|
|
|
return mongoose.connection.readyState == 1;
|
2022-04-04 20:15:43 -05:00
|
|
|
}
|