22 lines
646 B
TypeScript
22 lines
646 B
TypeScript
import { MongoClient } from "mongodb";
|
|
|
|
// Production MongoDB connection
|
|
const uri =
|
|
"mongodb://mo1124_ai_web:~4nfR5EA)3%C2%A3%40@mongo76.mydevil.net:27017/mo1124_ai_web?authSource=mo1124_ai_web";
|
|
|
|
// Use global variable to preserve connection across HMR in development
|
|
let globalWithMongo = global as typeof globalThis & {
|
|
_mongoClientPromise?: Promise<MongoClient>;
|
|
};
|
|
|
|
let clientPromise: Promise<MongoClient>;
|
|
|
|
if (!globalWithMongo._mongoClientPromise) {
|
|
const client = new MongoClient(uri);
|
|
globalWithMongo._mongoClientPromise = client.connect();
|
|
}
|
|
|
|
clientPromise = globalWithMongo._mongoClientPromise;
|
|
|
|
export default clientPromise;
|