Skip to content

Commit 463e3b2

Browse files
committed
Use SSL for postgres production connections
1 parent 51498e9 commit 463e3b2

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## [3.3.4] Mar-15-2021
44

55
### Fixes
6-
6+
- Use SSL for postgres production connections
77

88
## [3.3.3]
99

src/database/postgres.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ export class PointyPostgres extends BaseDb {
1717
public connect(options?: string | Object): Promise<Connection> {
1818
return new Promise(async (accept, reject) => {
1919
let pgOptions: any;
20+
let useSSL = false;
2021

2122
if (process.env.DATABASE_URL) {
2223
// Live
2324
pgOptions = PostgressConnectionStringParser.parse(
2425
process.env.DATABASE_URL
2526
);
2627
pgOptions.type = 'postgres';
28+
useSSL = true;
2729

2830
this.logger('Using production database');
2931
this.logger(
@@ -52,8 +54,7 @@ export class PointyPostgres extends BaseDb {
5254
this.shouldSync = true;
5355
}
5456

55-
// Create connection
56-
const conn = await createConnection(<ConnectionOptions>{
57+
options = {
5758
name: this.connectionName,
5859
type: process.env.TYPEORM_DRIVER_TYPE || pgOptions.type,
5960
driver: process.env.TYPEORM_DRIVER_TYPE || pgOptions.type,
@@ -66,11 +67,17 @@ export class PointyPostgres extends BaseDb {
6667
synchronize: this.shouldSync,
6768
uuidExtension: pgOptions.uuidExtension
6869
? pgOptions.uuidExtension
69-
: 'pgcrypto',
70-
ssl: {
70+
: 'pgcrypto'
71+
};
72+
73+
if (useSSL) {
74+
options['ssl'] = {
7175
rejectUnauthorized: false
72-
}
73-
}).catch((error) => {
76+
};
77+
}
78+
79+
// Create connection
80+
const conn = await createConnection(<ConnectionOptions>options).catch((error) => {
7481
reject(error);
7582
return false;
7683
});

0 commit comments

Comments
 (0)