Skip to content

Commit

Permalink
fix: use config to load credentials for db
Browse files Browse the repository at this point in the history
Signed-off-by: Anmol Sharma <anmolsharma0234@gmail.com>
  • Loading branch information
theanmolsharma committed Apr 14, 2024
1 parent 142add8 commit 4e89610
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 63 deletions.
7 changes: 7 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
db:
host: <host>
port: <port>
username: <username>
password: <password>
databaseName: silent-pay-indexer
synchronize: false
7 changes: 7 additions & 0 deletions config/dev.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
db:
host: localhost
port: 5432
username: root
password: password
databaseName: silent-pay-indexer
synchronize: false
8 changes: 7 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"webpack": true,
"webpackConfigPath": "webpack.config.js",
"builder": "webpack",
"deleteOutDir": true
"deleteOutDir": true,
"assets": [
{
"include": "../config/*",
"outDir": "./dist/config"
}
]
}
}
113 changes: 62 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch",
"start:debug": "nest build --webpack --webpackPath webpack-hmr.config.js --debug --watch",
"start:dev": "NODE_ENV=dev nest build --webpack --webpackPath webpack-hmr.config.js --watch",
"start:debug": "NODE_ENV=dev nest build --webpack --webpackPath webpack-hmr.config.js --debug --watch",
"start:prod": "node dist/main",
"format:check": "prettier --check \"src/**/*.ts\"",
"format:fix": "prettier --write --loglevel=silent \"src/**/*.ts\"",
Expand All @@ -24,6 +24,7 @@
},
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.3.7",
"@nestjs/microservices": "^10.3.7",
"@nestjs/passport": "^9.0.3",
Expand All @@ -33,6 +34,7 @@
"@nestjs/swagger": "^7.3.1",
"@nestjs/typeorm": "^10.0.2",
"@nestjs/websockets": "^10.3.7",
"js-yaml": "^4.1.0",
"pg": "^8.11.5",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
Expand All @@ -44,6 +46,7 @@
"@nestjs/testing": "^10.3.7",
"@types/express": "^4.17.13",
"@types/jest": "29.5.0",
"@types/js-yaml": "^4.0.9",
"@types/node": "18.15.11",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down
29 changes: 20 additions & 9 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ import { Module } from '@nestjs/common';
import { AppController } from '@/app.controller';
import { AppService } from '@/app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import configuration from '@/configuration';

@Module({
imports: [
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'root',
password: 'password',
database: 'silent-pay-indexer',
synchronize: true,
autoLoadEntities: true,
ConfigModule.forRoot({
ignoreEnvFile: true,
load: [configuration],
isGlobal: true,
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
type: 'postgres',
host: configService.get<string>('db.host'),
port: configService.get<number>('db.port'),
username: configService.get<string>('db.username'),
password: configService.get<string>('db.password'),
database: configService.get<string>('db.databaseName'),
synchronize: configService.get<boolean>('db.synchronize'),
autoLoadEntities: true,
}),
}),
],
controllers: [AppController],
Expand Down
Loading

0 comments on commit 4e89610

Please sign in to comment.