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