generated from kriasoft/react-firebase-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
knexfile.js
69 lines (60 loc) · 2.18 KB
/
knexfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* React Starter Kit for Firebase
* https://github.com/kriasoft/react-firebase-starter
* Copyright (c) 2015-present Kriasoft | MIT License
*/
const fs = require('fs');
const cp = require('child_process');
const dotenv = require('dotenv');
const { env = 'dev' } = require('minimist')(process.argv.slice(2));
function getProjectID(env) {
return `example-${env}`;
}
// Load API keys, secrets etc. from Firebase environment
// https://firebase.google.com/docs/functions/config-env
if (env === 'prod' || env === 'test') {
const { status, stdout } = cp.spawnSync(
'firebase',
[`--project=${getProjectID(env)}`, 'functions:config:get'],
{ stdio: ['pipe', 'pipe', 'inherit'] },
);
if (status !== 0) process.exit(status);
const config = JSON.parse(stdout.toString()).app;
Object.keys(config).forEach(key => {
process.env[key.toUpperCase()] =
typeof key === 'object' ? JSON.stringify(config[key]) : config[key];
});
process.env.PGHOST = 'X.X.X.X';
process.env.PGPOST = '5432';
process.env.PGSSLMODE = 'require';
process.env.PGSSLCERT = `./ssl/${env}.client-cert.pem`;
process.env.PGSSLKEY = `./ssl/${env}.client-key.pem`;
process.env.PGSSLROOTCERT = `./ssl/${env}.server-ca.pem`;
} else if (env === 'local') {
dotenv.config({ path: '.env.local' });
process.env.PGPORT = process.env.PGPORT || '5432';
process.env.PGHOST = process.env.PGHOST || 'localhost';
process.env.PGUSER = process.env.PGUSER || 'postgres';
process.env.PGPASSWORD = process.env.PGPASSWORD || '';
process.env.PGDATABASE = process.env.PGDATABASE || 'rsk_local';
process.env.PGSSLMODE = process.env.PGSSLMODE || 'disable';
}
console.log('Environment:', env);
dotenv.config({ path: '.env' });
// Knex configuration that is used with DB migration scripts etc.
// http://knexjs.org/#knexfile
module.exports = {
client: 'pg',
migrations: {
tableName: 'migrations',
},
connection: {
max: 1,
ssl: (process.env.PGSSLMODE || 'disable') !== 'disable' && {
rejectUnauthorized: false,
cert: fs.readFileSync(process.env.PGSSLCERT, 'utf8'),
key: fs.readFileSync(process.env.PGSSLKEY, 'utf8'),
ca: fs.readFileSync(process.env.PGSSLROOTCERT, 'utf8'),
},
},
};