aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.ts
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2021-04-19 14:51:34 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2021-04-19 14:51:34 +0300
commit7f3a70c396b498a8b10553d11cf78c3ea9a872b1 (patch)
tree29e8063a080b1bb83bd92a5cc8ff8f5365b186e7 /src/config.ts
parent2725e84e199e1d0b5e6ce01e405c035481e49c0d (diff)
Should be ready now
Diffstat (limited to 'src/config.ts')
-rw-r--r--src/config.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/config.ts b/src/config.ts
index 962fd49..8766db9 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -1,4 +1,6 @@
import dotenv from "dotenv";
+import fs from "fs";
+import path from "path";
if (!process.env.SKIP_DOTENV) {
dotenv.config();
@@ -36,6 +38,17 @@ if (!pgConnectionUri) {
throw new ConfigError("Missing env var PG_CONNECTION_URI");
}
+const googleSaJsonB64 = process.env.G_SA_JSON_B64 || null;
+if (!googleSaJsonB64) {
+ throw new ConfigError("Missing env var G_SA_JSON_B64");
+}
+
+const googleSaJsonBuff = Buffer.from(googleSaJsonB64, "base64");
+const googleSaJsonUtf8 = googleSaJsonBuff.toString("utf-8");
+const googleSaJson: Record<string, string> = JSON.parse(googleSaJsonUtf8);
+const googleSaJsonPath = path.join("sa_key.json");
+fs.writeFileSync(googleSaJsonPath, googleSaJsonUtf8);
+
const config = {
port: process.env.PORT ? Number(process.env.PORT) : 3000,
tgWebhookUrl,
@@ -43,6 +56,8 @@ const config = {
sheetsSpreadsheetId,
sheetsRange,
pgConnectionUri,
+ googleSaJson,
+ googleSaJsonPath,
};
export default config;