fix: Restore Postgres SSL support on Heroku

https://github.com/brianc/node-postgres/issues/2009
This commit is contained in:
Tom Moor 2020-08-22 08:27:42 -07:00
parent ec55299c8b
commit c446a91f7d
2 changed files with 16 additions and 2 deletions

View File

@ -9,6 +9,11 @@
},
"production": {
"use_env_variable": "DATABASE_URL",
"dialect": "postgres"
"dialect": "postgres",
"dialectOptions": {
"ssl": {
"rejectUnauthorized": false
}
}
}
}

View File

@ -3,6 +3,8 @@ import debug from "debug";
import Sequelize from "sequelize";
import EncryptedField from "sequelize-encrypted";
const isProduction = process.env.NODE_ENV === "production";
export const encryptedFields = () =>
EncryptedField(Sequelize, process.env.SECRET_KEY);
@ -10,7 +12,14 @@ export const DataTypes = Sequelize;
export const Op = Sequelize.Op;
export const sequelize = new Sequelize(process.env.DATABASE_URL, {
// logging: console.log,
logging: debug("sql"),
typeValidation: true,
dialectOptions: {
ssl: isProduction
? {
// Ref.: https://github.com/brianc/node-postgres/issues/2009
rejectUnauthorized: false,
}
: false,
},
});