blob: ca60b9704699a6636c5c322cbcb8c752ae109089 (
plain)
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
|
import dotenv from "dotenv";
import fs from "fs";
import path from "path";
if (!process.env.SKIP_DOTENV) {
dotenv.config();
}
class ConfigError extends Error {
constructor(message: string) {
super(message);
this.name = "ConfigError";
}
}
const nodeEnv = process.env.NODE_ENV || "development";
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
const tgWebhookUrl = process.env.TELEGRAM_WEBHOOK_URL || null;
if (!tgWebhookUrl) {
throw new ConfigError("Missing env var TELEGRAM_WEBHOOK_URL");
}
const tgBotToken = process.env.TELEGRAM_BOT_TOKEN || null;
if (!tgBotToken) {
throw new ConfigError("Missing env var TELEGRAM_BOT_TOKEN");
}
const sheetsSpreadsheetId = process.env.SHEETS_SPREADSHEET_ID || null;
if (!sheetsSpreadsheetId) {
throw new ConfigError("Missing env var SHEETS_SPREADSHEET_ID");
}
const sheetsRange = process.env.SHEETS_RANGE || null;
if (!sheetsRange) {
throw new ConfigError("Missing env var SHEETS_RANGE");
}
const pgConnectionUri = process.env.PG_CONNECTION_URI || null;
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 = {
nodeEnv,
port,
tgWebhookUrl,
tgBotToken,
sheetsSpreadsheetId,
sheetsRange,
pgConnectionUri,
googleSaJson,
googleSaJsonPath,
};
export default config;
|