Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: trust SSL certificate by default to ease users onboarding (#472)
- Loading branch information
1 parent
c351ab3
commit 2cf7e6b
Showing
6 changed files
with
98 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
APPLICATION_PORT=1654 | ||
|
||
CORS_ORIGINS= | ||
|
||
DATABASE_URL=postgres://localhost:27017 | ||
DATABASE_SCHEMA=public | ||
DATABASE_SSL=false | ||
# This should be removed in production environment. | ||
DATABASE_REJECT_UNAUTHORIZED=false | ||
|
||
FOREST_AUTH_SECRET= | ||
FOREST_ENV_SECRET= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Sequelize = require('sequelize'); | ||
|
||
if (!process.env.DATABASE_URL) { | ||
console.error('Cannot connect to the database. Please declare the DATABASE_URL environment variable with the correct database connection string.'); | ||
process.exit(); | ||
} | ||
|
||
const databaseOptions = { | ||
logging: process.env.NODE_ENV === 'development' ? console.log : false, | ||
pool: { maxConnections: 10, minConnections: 1 }, | ||
dialectOptions: {}, | ||
}; | ||
|
||
if (process.env.DATABASE_SSL && JSON.parse(process.env.DATABASE_SSL.toLowerCase())) { | ||
if (process.env.DATABASE_REJECT_UNAUTHORIZED === false) { | ||
databaseOptions.dialectOptions.ssl = { rejectUnauthorized: false }; | ||
} else { | ||
databaseOptions.dialectOptions.ssl = true; | ||
} | ||
} | ||
|
||
const sequelize = new Sequelize(process.env.DATABASE_URL, databaseOptions); | ||
const db = {}; | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter((file) => { | ||
return (file.indexOf('.') !== 0) && (file !== 'index.js'); | ||
}) | ||
.forEach((file) => { | ||
try { | ||
const model = sequelize.import(path.join(__dirname, file)); | ||
db[model.name] = model; | ||
} catch (error) { | ||
console.error('Model creation error: ' + error); | ||
} | ||
}); | ||
|
||
Object.keys(db).forEach((modelName) => { | ||
if ('associate' in db[modelName]) { | ||
db[modelName].associate(db); | ||
} | ||
}); | ||
|
||
db.sequelize = sequelize; | ||
db.Sequelize = Sequelize; | ||
|
||
module.exports = db; |
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