csc309-team58/sports-matcher/server/middleware/database.js

13 lines
334 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;
}