Skip to content

Commit 2e913c0

Browse files
committed
Add ssl ca
1 parent 695d76a commit 2e913c0

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ DATABASE_HOST=postgres
1212
DATABASE_NAME=ink
1313
DATABASE_USERNAME=root
1414
DATABASE_PASSWORD=password
15+
DATABASE_PORT=5432
16+
DATABASE_SSL_CA=""
1517
DATABASE_RETRY_ATTEMPTS=5
1618
DATABASE_RETRY_DELAY=3000
1719

src/db/db.module.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Module } from '@nestjs/common'
2-
import { TypeOrmModule } from '@nestjs/typeorm'
2+
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'
33
import { Block } from '../blocks/entity/block.entity'
44
import { Contract } from '../contracts/entity/contract.entity'
55
import { EnvModule } from '../env/env.module'
@@ -13,7 +13,7 @@ import { Transaction } from '../transactions/entity/transaction.entity'
1313
imports: [EnvModule],
1414
inject: [EnvService],
1515
useFactory: async (env: EnvService) => {
16-
return {
16+
const config: TypeOrmModuleOptions = {
1717
type: 'postgres',
1818
host: env.DATABASE_HOST,
1919
port: env.DATABASE_PORT,
@@ -26,6 +26,18 @@ import { Transaction } from '../transactions/entity/transaction.entity'
2626
autoLoadEntities: true,
2727
keepConnectionAlive: false,
2828
}
29+
30+
if (!env.isProduction()) {
31+
return config
32+
}
33+
34+
return {
35+
...config,
36+
ssl: {
37+
ca: env.DATABASE_SSL_CA,
38+
rejectUnauthorized: false,
39+
},
40+
}
2941
},
3042
}),
3143
TypeOrmModule.forFeature([Block, Transaction, Event, Contract]),

src/env/env.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class EnvService {
2323
public readonly DATABASE_PASSWORD: string
2424
public readonly DATABASE_RETRY_ATTEMPTS: number
2525
public readonly DATABASE_RETRY_DELAY: number
26+
public readonly DATABASE_SSL_CA: string
2627

2728
constructor(private readonly config: ConfigService) {
2829
// public env variables
@@ -42,6 +43,7 @@ export class EnvService {
4243
this.DATABASE_PASSWORD = this.config.get<string>('DATABASE_PASSWORD', 'password')
4344
this.DATABASE_RETRY_ATTEMPTS = parseInt(this.config.get<string>('DATABASE_RETRY_ATTEMPTS', '20'), 10)
4445
this.DATABASE_RETRY_DELAY = parseInt(this.config.get<string>('DATABASE_RETRY_DELAY', '6000'), 10)
46+
this.DATABASE_SSL_CA = this.config.get<string>('DATABASE_SSL_CA', '')
4547
}
4648

4749
public isProduction(): boolean {

src/env/env.validation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export class EnvironmentVariables {
5454

5555
@IsNumberString()
5656
DATABASE_RETRY_DELAY: string | undefined
57+
58+
@IsString()
59+
DATABASE_SSL_CA: string | undefined
5760
}
5861

5962
export function validate(config: Record<string, unknown>) {

0 commit comments

Comments
 (0)