fix: connection to db for heroku

This commit is contained in:
Sergey Yarkov 2022-03-23 23:54:00 +03:00
parent 6caec9beb3
commit 781b5aa157
2 changed files with 7 additions and 5 deletions

View File

@ -30,7 +30,7 @@ application.
- 1. Clone this repository `git clone https://github.com/sergeyyarkov/node-docker-example.git .` - 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 - 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 ## Requirements

10
db.js
View File

@ -6,12 +6,14 @@ class Database {
constructor() { constructor() {
this.client = new pg.Client({ this.client = new pg.Client({
connectionString: connectionString:
process.env.NODE_ENV === 'production' process.env.NODE_ENV === 'production' && process.env.DATABASE_URL
? process.env.DATABASE_URL ? process.env.DATABASE_URL
: connectionString, : connectionString,
ssl: { ssl: process.env.DATABASE_URL
rejectUnauthorized: false, ? {
}, rejectUnauthorized: false,
}
: false,
}); });
} }
} }