diff --git a/.env.sample b/.env.sample index e4879de..3563f76 100644 --- a/.env.sample +++ b/.env.sample @@ -7,6 +7,6 @@ ADMIN_PASSWORD=password WEBHOOKS_CACHE_TTL=300000 NODE_ENV=dev SSE_AUTH_TOKEN=aW5mcmFAc2FmZS5nbG9iYWw6YWJjMTIz -ENABLE_DB_SSL=false +DB_SSL_ENABLE=false # DB_CA_PATH=/path/of/db/certificate # URL_BASE_PATH=/test # Set a globlal url path diff --git a/src/datasources/db/database.options.ts b/src/datasources/db/database.options.ts index 0039d05..7d86a2a 100644 --- a/src/datasources/db/database.options.ts +++ b/src/datasources/db/database.options.ts @@ -1,7 +1,6 @@ import { Webhook } from '../../routes/webhook/entities/webhook.entity'; import { DataSourceOptions } from 'typeorm'; -import * as fs from 'fs'; - +import { readFileSync } from 'fs'; /** * Use process.env for configuration instead of Nest.js ConfigService * as it cannot be used by TypeORM CLI to generate and run migrations @@ -11,23 +10,19 @@ export const dataSourceOptions: DataSourceOptions = { url: process.env.MIGRATIONS_DATABASE_URL, entities: [Webhook], migrations: [__dirname + '/../migrations/**/*{.ts,.js}'], - ... (process.env.DB_SSL_ENABLE == 'true' ? { - ssl: true, - ... (process.env.DB_CA_PATH ? { - extra: { - ssl: { - ca: fs.readFileSync(process.env.DB_CA_PATH), - rejectUnauthorized: true - } - } - } : { - extra: { - ssl: { - rejectUnauthorized: false - } - } - }) - }:{ - ssl: false - }) -}; \ No newline at end of file + extra: + process.env.DB_SSL_ENABLE !== 'true' + ? {} + : process.env.DB_CA_PATH + ? { + ssl: { + ca: readFileSync(process.env.DB_CA_PATH), + rejectUnauthorized: true, + }, + } + : { + ssl: { + rejectUnauthorized: false, + }, + }, +};