fix(mongoose): fall back to process.env when run outside Nitro
connectDB() called useRuntimeConfig() unconditionally — works inside the Nuxt/Nitro runtime but throws ReferenceError for standalone Node scripts (seed-members.js, seed-tags.js, etc.). CI exposed this when trying to run seed-all.js. Detect the auto-import and fall back to process.env when it's not available; preserves Nitro behavior.
This commit is contained in:
parent
f66189cfd6
commit
6bfb078e45
1 changed files with 4 additions and 1 deletions
|
|
@ -7,7 +7,10 @@ export const connectDB = async () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const MONGODB_URI = useRuntimeConfig().mongodbUri;
|
||||
const MONGODB_URI =
|
||||
typeof useRuntimeConfig === 'function'
|
||||
? useRuntimeConfig().mongodbUri
|
||||
: process.env.NUXT_MONGODB_URI || process.env.MONGODB_URI;
|
||||
|
||||
try {
|
||||
await mongoose.connect(MONGODB_URI, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue