Last active
March 21, 2021 06:33
-
-
Save cyjeff/a438e591540453c5815d0165a61ac7bf to your computer and use it in GitHub Desktop.
SSL setting for Knex.js to postgreSQL on Heroku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const knex = require("knex"); | |
const parse = require("pg-connection-string").parse; | |
// Parse the environment variable into an object containing User, Password, Host, Port etc at separate key-value pairs | |
const pgconfig = parse(process.env.DATABASE_URL); | |
// Add SSL setting to default environment variable on a new key-value pair (the value itself is an object) | |
pgconfig.ssl = { rejectUnauthorized: false }; | |
const db = knex({ | |
client: "pg", | |
connection: pgconfig, | |
}); | |
module.exports = db; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment