ghostguild-org/server/utils/mongoose.js
Jennie Robinson Faber 04eb33df6e
Some checks failed
Test / vitest (push) Successful in 11m10s
Test / playwright (push) Failing after 14m51s
Test / visual (push) Failing after 11m1s
Test / Notify on failure (push) Successful in 3s
refactor(env): unify required-env validation through useRuntimeConfig
validate-env.js now reads all four required vars (MONGODB_URI, JWT_SECRET,
RESEND_API_KEY, HELCIM_API_TOKEN) from useRuntimeConfig() instead of mixing
direct process.env reads with a JWT-only special case. Mongoose and the six
Resend instantiations follow suit. Either bare or NUXT_-prefixed env names
are accepted, so Dokploy no longer needs duplicate entries.
2026-04-26 14:47:02 +01:00

24 lines
No EOL
487 B
JavaScript

import mongoose from 'mongoose';
let isConnected = false;
export const connectDB = async () => {
if (isConnected) {
return;
}
const MONGODB_URI = useRuntimeConfig().mongodbUri;
try {
await mongoose.connect(MONGODB_URI, {
serverSelectionTimeoutMS: 5000,
});
isConnected = true;
console.log('MongoDB connected successfully');
} catch (error) {
console.error('MongoDB connection error:', error);
throw error;
}
};
export default connectDB;