mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-13 08:56:53 +02:00
First public commit
This commit is contained in:
commit
e05cd62e53
228 changed files with 17717 additions and 0 deletions
32
utils/mongodb-client.ts
Normal file
32
utils/mongodb-client.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Import the dependency.
|
||||
import { MongoClient } from "mongodb";
|
||||
|
||||
declare global {
|
||||
// allow global `var` declarations
|
||||
// eslint-disable-next-line no-var
|
||||
var _mongoClientPromise: Promise<MongoClient>;
|
||||
}
|
||||
|
||||
const uri = process.env.LEGACY_MONGODB_URI;
|
||||
|
||||
let client;
|
||||
let clientPromise;
|
||||
|
||||
export const getMongoClient = async () => {
|
||||
if (!uri) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (global._mongoClientPromise) {
|
||||
return global._mongoClientPromise;
|
||||
}
|
||||
|
||||
client = new MongoClient(uri);
|
||||
clientPromise = client.connect();
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
global._mongoClientPromise = clientPromise;
|
||||
}
|
||||
|
||||
return clientPromise;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue