Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Created December 2, 2023 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GoodnessEzeokafor/51fe463ecaa079179862b6a2f17ffc65 to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/51fe463ecaa079179862b6a2f17ffc65 to your computer and use it in GitHub Desktop.
Connecting to postgresql db with ssl
import { DataSource } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { config } from 'dotenv';
import models from '../../models';
config();
const configService = new ConfigService();
export default new DataSource({
type: 'postgres',
host: configService.get('DB_HOST'),
port: configService.get('DB_PORT'),
username: configService.get('DB_USER'),
password: configService.get('DB_PASSWORD'),
database: configService.get('DB_NAME'),
entities: models,
migrations: [__dirname + '/migrations/staging/*.ts'],
ssl: {
rejectUnauthorized: false,
ca: configService.get('POSTGRES_SQL_CERT').replace(/[\r\n]/gm, ''),
},
synchronize: false,
migrationsRun: true,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment