Skip to content

Commit

Permalink
Add configuration for SSL database connection (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 authored Jan 15, 2024
1 parent 2f81769 commit 6997615
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ADMIN_PASSWORD=password
WEBHOOKS_CACHE_TTL=300000
NODE_ENV=dev
SSE_AUTH_TOKEN=aW5mcmFAc2FmZS5nbG9iYWw6YWJjMTIz
DATABASE_SSL_ENABLED=false
# DATABASE_CA_PATH=/path/of/db/certificate
# URL_BASE_PATH=/test # Set a globlal url path
14 changes: 13 additions & 1 deletion src/datasources/db/database.options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Webhook } from '../../routes/webhook/entities/webhook.entity';
import { DataSourceOptions } from 'typeorm';

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
Expand All @@ -10,4 +10,16 @@ export const dataSourceOptions: DataSourceOptions = {
url: process.env.MIGRATIONS_DATABASE_URL,
entities: [Webhook],
migrations: [__dirname + '/../migrations/**/*{.ts,.js}'],
...(process.env.DATABASE_SSL_ENABLED == 'true'
? {
ssl: process.env.DATABASE_CA_PATH
? {
ca: readFileSync(process.env.DATABASE_CA_PATH),
rejectUnauthorized: true,
}
: {
rejectUnauthorized: false,
},
}
: {}),
};

0 comments on commit 6997615

Please sign in to comment.