There was an error while loading. Please reload this page.
1 parent e56f053 commit 4d039e4Copy full SHA for 4d039e4
1 file changed
lib/db.ts
@@ -2,10 +2,6 @@ import mongoose from 'mongoose';
2
3
const MONGODB_URI = process.env.MONGODB_URI;
4
5
-if (!MONGODB_URI) {
6
- throw new Error('Please define the MONGODB_URI environment variable inside .env.local');
7
-}
8
-
9
interface MongooseCache {
10
conn: mongoose.Connection | null;
11
promise: Promise<mongoose.Connection> | null;
@@ -22,6 +18,10 @@ if (!cached) {
22
18
}
23
19
24
20
async function dbConnect() {
21
+ if (!MONGODB_URI) {
+ throw new Error('Please define the MONGODB_URI environment variable inside .env.local');
+ }
+
25
if (cached.conn) {
26
return cached.conn;
27
0 commit comments