mirror of
https://github.com/sasjs/server.git
synced 2026-01-08 23:10:05 +00:00
29 lines
651 B
TypeScript
29 lines
651 B
TypeScript
import mongoose from 'mongoose'
|
|
import { populateClients } from '../routes/api/auth'
|
|
import { seedDB } from './seedDB'
|
|
|
|
export const connectDB = () => {
|
|
// NOTE: when exporting app.js as agent for supertest
|
|
// we should exclude connecting to the real database
|
|
if (process.env.NODE_ENV === 'test') {
|
|
return
|
|
}
|
|
|
|
const { MODE } = process.env
|
|
|
|
if (MODE?.trim() !== 'server') {
|
|
console.log('Running in Destop Mode, no DB to connect.')
|
|
return
|
|
}
|
|
|
|
mongoose.connect(process.env.DB_CONNECT as string, async (err) => {
|
|
if (err) throw err
|
|
|
|
console.log('Connected to db!')
|
|
|
|
await seedDB()
|
|
|
|
await populateClients()
|
|
})
|
|
}
|