blob: 6f142e5706eac38416fcd8cc115fb8271507ec36 (
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
68
69
70
71
72
73
74
75
76
77
78
|
import fs from "fs";
import toml from "toml";
import { exitWithError } from "./process.js";
interface StaticPage {
title: string;
path: string;
filename: string;
}
interface GathioConfig {
general: {
domain: string;
port: string;
email: string;
site_name: string;
is_federated: boolean;
email_logo_url: string;
show_kofi: boolean;
mail_service: "nodemailer" | "sendgrid";
};
database: {
mongodb_url: string;
};
nodemailer?: {
smtp_server: string;
smtp_port: string;
smtp_username: string;
smtp_password: string;
};
sendgrid?: {
api_key: string;
};
static_pages: StaticPage[];
}
interface FrontendConfig {
domain: string;
siteName: string;
isFederated: boolean;
emailLogoUrl: string;
showKofi: boolean;
showInstanceInformation: boolean;
staticPages: StaticPage[];
version: string;
}
export const frontendConfig = (): FrontendConfig => {
const config = getConfig();
return {
domain: config.general.domain,
siteName: config.general.site_name,
isFederated: config.general.is_federated,
emailLogoUrl: config.general.email_logo_url,
showKofi: config.general.show_kofi,
showInstanceInformation: config.static_pages?.length > 0,
staticPages: config.static_pages,
version: process.env.npm_package_version || "unknown",
};
};
// Attempt to load our global config. Will stop the app if the config file
// cannot be read (there's no point trying to continue!)
export const getConfig = (): GathioConfig => {
try {
const config = toml.parse(
fs.readFileSync("./config/config.toml", "utf-8"),
) as GathioConfig;
return config;
} catch {
exitWithError(
"Configuration file not found! Have you renamed './config/config-example.toml' to './config/config.toml'?",
);
return process.exit(1);
}
};
export default getConfig;
|