13 lines
333 B
JavaScript
13 lines
333 B
JavaScript
import mongoose from "mongoose";
|
|
|
|
export function needDatabase(req, res, next) {
|
|
if (checkDatabaseConnection()) {
|
|
res.status(500).send("Internal server error: Database connection faulty.");
|
|
} else {
|
|
next();
|
|
}
|
|
}
|
|
|
|
export function checkDatabaseConnection() {
|
|
return mongoose.connection.readyState == 1;
|
|
} |