diff --git a/app/persistence/postgreSQL/PgService.ts b/app/persistence/postgreSQL/PgService.ts index 7269b47f8..98d5c1a50 100644 --- a/app/persistence/postgreSQL/PgService.ts +++ b/app/persistence/postgreSQL/PgService.ts @@ -97,10 +97,26 @@ export class PgService { * @memberof PgService */ getUserModel(attributes, options) { - const sequelize = new Sequelize( - `postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`, - { logging: false } - ); + + // Add SSL option for PostGresql- Issue #404 + const isPostgresSslEnabled = process.env.DATABASE_SSL_ENABLED || false; + + if (isPostgresSslEnabled) { + logger.info('SSL to Postgresql enabled: set dialect SSL option'); + const sequelize = new Sequelize( + `postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`, + { logging: false, dialectOptions: { ssl: true, }, } + ); + }else{ + logger.info('SSL to Postgresql disabled: dialect options not set'); + const sequelize = new Sequelize( + `postgres://${this.pgconfig.user}:${this.pgconfig.password}@${this.pgconfig.host}:${this.pgconfig.port}/${this.pgconfig.database}`, + { logging: false } + ); + + } + + this.userModel = sequelize.define('users', attributes, options); return this.userModel; }