Skip to content

Commit

Permalink
Merge pull request #58 from Blvckleg/mongo-config
Browse files Browse the repository at this point in the history
fix(mongo): configurable auth-database
  • Loading branch information
lulu12329 authored Feb 25, 2024
2 parents 1b3c9df + ee35cd4 commit e5d1e36
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
36 changes: 30 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
"runtimeExecutable": "npm",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"runtimeArgs": ["run-script", "start:debug"],
"skipFiles": ["<node_internals>/**"]
"runtimeArgs": [
"run-script",
"start:debug"
],
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
Expand All @@ -21,9 +26,28 @@
"runtimeExecutable": "npm",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env.dev",
"runtimeArgs": ["run-script", "start:debug"],
"skipFiles": ["<node_internals>/**"]
"runtimeArgs": [
"run-script",
"start:debug"
],
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"request": "launch",
"name": "start:lukas",
"runtimeExecutable": "npm",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env.lukas",
"runtimeArgs": [
"run-script",
"start:debug"
],
"skipFiles": [
"<node_internals>/**"
]
}
]

}
}
5 changes: 1 addition & 4 deletions src/config/database/mongo/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ const ENV = process.env.NODE_ENV;
MONGO_PORT: Joi.number().default(27017),
MONGO_USERNAME: Joi.string(),
MONGO_PASSWORD: Joi.string(),
MONGO_DATABASE: Joi.string().default('bingus'),
MONGO_RUN_MIGRATION: Joi.boolean().default(false),
MONGO_ENTITIES: Joi.string().default('dist/**/*.entity.*{ts,js}'),
MONGO_RUN_SYNCHRONIZE: Joi.boolean().default(false),
MONGO_DATABASE: Joi.string().default(null),
}),
}),
],
Expand Down
18 changes: 2 additions & 16 deletions src/config/database/mongo/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import {
*/
@Injectable()
export class MongoConfigService implements MongooseOptionsFactory {
constructor(private configService: ConfigService) {}
constructor(private configService: ConfigService) { }

createMongooseOptions(): MongooseModuleOptions {
if (this.username && this.password) {
return {
uri: `mongodb://${this.username}:${this.password}@${this.uri}`,
};
return { uri: `mongodb://${this.username}:${this.password}@${this.uri}` + (this.database ? `/?authSource=${this.database}` : "") }
} else {
return { uri: this.uri };
}
Expand All @@ -26,9 +24,6 @@ export class MongoConfigService implements MongooseOptionsFactory {
get uri(): string {
return this.configService.get<string>('mongo.uri');
}
get port(): number {
return Number(this.configService.get<number>('mongo.port'));
}
get username(): string {
return this.configService.get<string>('mongo.username');
}
Expand All @@ -38,13 +33,4 @@ export class MongoConfigService implements MongooseOptionsFactory {
get database(): string {
return this.configService.get<string>('mongo.database');
}
get migrationsRun(): boolean {
return JSON.parse(this.configService.get<string>('mongo.migrationsRun'));
}
get synchronizeRun(): boolean {
return JSON.parse(this.configService.get<string>('mongo.synchronizeRun'));
}
get entities(): string {
return this.configService.get<string>('mongo.entities');
}
}

0 comments on commit e5d1e36

Please sign in to comment.