From 781b5aa157b89c218bb6c6cf2eca503814598067 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Wed, 23 Mar 2022 23:54:00 +0300 Subject: [PATCH] fix: connection to db for heroku --- README.md | 2 +- db.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 74870db..4db2f86 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ application. - 1. Clone this repository `git clone https://github.com/sergeyyarkov/node-docker-example.git .` - 2. Configure enviroment variables in `docker-compose.yml` for `postgres` and `nodejs` serivces if you need to -- 3. Build and run application with `docker compose up --build` +- 3. Build and run application with `docker-compose up --build` ## Requirements diff --git a/db.js b/db.js index 5334ffb..1a09f18 100644 --- a/db.js +++ b/db.js @@ -6,12 +6,14 @@ class Database { constructor() { this.client = new pg.Client({ connectionString: - process.env.NODE_ENV === 'production' + process.env.NODE_ENV === 'production' && process.env.DATABASE_URL ? process.env.DATABASE_URL : connectionString, - ssl: { - rejectUnauthorized: false, - }, + ssl: process.env.DATABASE_URL + ? { + rejectUnauthorized: false, + } + : false, }); } }