feat(Mongo): Config variable can disable MongoDB usage and dependency in Docker

This commit is contained in:
Chris Troutner
2024-06-09 08:28:40 -07:00
parent f7aaba71d1
commit 0a7ec11510
3 changed files with 31 additions and 20 deletions
+17 -13
View File
@@ -45,16 +45,18 @@ class Server {
const app = new Koa() const app = new Koa()
app.keys = [this.config.session] app.keys = [this.config.session]
// Connect to the Mongo Database. if (!this.config.noMongo) {
this.mongoose.Promise = global.Promise // Connect to the Mongo Database.
this.mongoose.set('useCreateIndex', true) // Stop deprecation warning. this.mongoose.Promise = global.Promise
console.log( this.mongoose.set('useCreateIndex', true) // Stop deprecation warning.
`Connecting to MongoDB with this connection string: ${this.config.database}` console.log(
) `Connecting to MongoDB with this connection string: ${this.config.database}`
await this.mongoose.connect(this.config.database, { )
useUnifiedTopology: true, await this.mongoose.connect(this.config.database, {
useNewUrlParser: true useUnifiedTopology: true,
}) useNewUrlParser: true
})
}
console.log(`Starting environment: ${this.config.env}`) console.log(`Starting environment: ${this.config.env}`)
console.log(`Debug level: ${this.config.debugLevel}`) console.log(`Debug level: ${this.config.debugLevel}`)
@@ -102,9 +104,11 @@ class Server {
this.server = await app.listen(this.config.port) this.server = await app.listen(this.config.port)
console.log(`Server started on ${this.config.port}`) console.log(`Server started on ${this.config.port}`)
// Create the system admin user. if (!this.config.noMongo) {
const success = await this.adminLib.createSystemUser() // Create the system admin user.
if (success) console.log('System admin user created.') const success = await this.adminLib.createSystemUser()
if (success) console.log('System admin user created.')
}
// Attach the other IPFS controllers. // Attach the other IPFS controllers.
// Skip if this is a test environment. // Skip if this is a test environment.
+3
View File
@@ -43,6 +43,9 @@ export default {
? process.env.EMAILPASS ? process.env.EMAILPASS
: 'emailpassword', : 'emailpassword',
// Enable or Disable the usage of Mongo DB.
noMongo: process.env.NO_MONGO ? true : false,
// BEGIN WALLET CONFIGURATION // BEGIN WALLET CONFIGURATION
// BCH Mnemonic for generating encryption keys and payment address // BCH Mnemonic for generating encryption keys and payment address
+11 -7
View File
@@ -12,6 +12,7 @@ import UserRouter from './users/index.js'
import ContactRESTController from './contact/index.js' import ContactRESTController from './contact/index.js'
import LogsRESTController from './logs/index.js' import LogsRESTController from './logs/index.js'
import IpfsRESTController from './ipfs/index.js' import IpfsRESTController from './ipfs/index.js'
import config from '../../../config/index.js'
class RESTControllers { class RESTControllers {
constructor (localConfig = {}) { constructor (localConfig = {}) {
@@ -29,7 +30,8 @@ class RESTControllers {
) )
} }
// console.log('Controllers localConfig: ', localConfig) // Encapsulate dependencies
this.config = config
} }
attachRESTControllers (app) { attachRESTControllers (app) {
@@ -38,13 +40,15 @@ class RESTControllers {
useCases: this.useCases useCases: this.useCases
} }
// Attach the REST API Controllers associated with the /auth route if (!this.config.noMongo) {
const authRESTController = new AuthRESTController(dependencies) // Attach the REST API Controllers associated with the /auth route
authRESTController.attach(app) const authRESTController = new AuthRESTController(dependencies)
authRESTController.attach(app)
// Attach the REST API Controllers associated with the /user route // Attach the REST API Controllers associated with the /user route
const userRouter = new UserRouter(dependencies) const userRouter = new UserRouter(dependencies)
userRouter.attach(app) userRouter.attach(app)
}
// Attach the REST API Controllers associated with the /contact route // Attach the REST API Controllers associated with the /contact route
const contactRESTController = new ContactRESTController(dependencies) const contactRESTController = new ContactRESTController(dependencies)