forked from UKSOURCE/ipv6
Adding UI of FeedBack, Registration, Admin console
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
/** Cached connection for Next.js hot reload (global is preserved across HMR). */
|
||||
const globalForMongoose = globalThis as typeof globalThis & {
|
||||
mongooseConn?: typeof mongoose;
|
||||
};
|
||||
|
||||
export default async function connectDB(): Promise<typeof mongoose> {
|
||||
const uri = process.env.MONGODB_URI;
|
||||
if (!uri) {
|
||||
throw new Error("MONGODB_URI is not set. Add it to .env (e.g. mongodb://localhost:27017/ipv6_summit).");
|
||||
}
|
||||
|
||||
if (globalForMongoose.mongooseConn?.connection?.readyState === 1) {
|
||||
return globalForMongoose.mongooseConn;
|
||||
}
|
||||
|
||||
const conn = await mongoose.connect(uri);
|
||||
globalForMongoose.mongooseConn = conn;
|
||||
return conn;
|
||||
}
|
||||
Reference in New Issue
Block a user