forked from kriasoft/graphql-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.cjs
More file actions
41 lines (34 loc) · 1.19 KB
/
Copy pathindex.cjs
File metadata and controls
41 lines (34 loc) · 1.19 KB
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
/**
* Loads environment variables from .env files into `process.env`.
*
* @see https://github.com/motdotla/dotenv
* @copyright 2016-present Kriasoft (https://git.io/vMINh)
*/
const fs = require("fs");
const path = require("path");
const dotenv = require("dotenv");
const minimist = require("minimist");
const args = minimist(process.argv.slice(2));
const env = args.env || minimist(args._).env || "dev";
dotenv.config({ path: path.resolve(__dirname, `.env.${env}.override`) });
dotenv.config({ path: path.resolve(__dirname, `.env.${env}`) });
dotenv.config({ path: path.resolve(__dirname, `.env`) });
// Load Google Cloud credentials
const gcpKey = path.resolve(__dirname, `gcp-key.${env}.json`);
if (fs.existsSync(gcpKey)) {
process.env.GOOGLE_APPLICATION_CREDENTIALS = gcpKey;
}
// Resolve relative paths to absolute
["PGSSLCERT", "PGSSLKEY", "PGSSLROOTCERT"].forEach((key) => {
if (process.env[key] && process.env[key].startsWith(".")) {
process.env[key] = path.resolve(__dirname, process.env[key]);
}
});
// Ensure that the SSL key file has correct permissions
if (process.env.PGSSLKEY) {
try {
fs.chmodSync(process.env.PGSSLKEY, 0o600);
} catch (err) {
console.error(err);
}
}