summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRaphael Kabo <mail@raphaelkabo.com>2023-05-13 19:19:37 +0100
committerRaphael Kabo <mail@raphaelkabo.com>2023-05-13 19:19:37 +0100
commit45ecdf59f8b0c4090041ce86aad2e5f606253f0d (patch)
tree77d1f3ea9acd0b23040f15bc757e9ba39c47af26 /src
parentf1a5a9b9a0f8357e25e3b2c8d72d745093bda9c3 (diff)
Migrate config library to TOML
Diffstat (limited to 'src')
-rw-r--r--src/config/api-example.js8
-rw-r--r--src/config/database-docker.js3
-rw-r--r--src/config/database-example.js3
-rw-r--r--src/config/domain-example.js13
-rw-r--r--src/config/gathio.service13
-rw-r--r--src/lib/config.ts56
6 files changed, 56 insertions, 40 deletions
diff --git a/src/config/api-example.js b/src/config/api-example.js
deleted file mode 100644
index 493b9d6..0000000
--- a/src/config/api-example.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Which of these fields are used depends on the 'mailService' config entry in config/domain.js
-module.exports = {
- sendgrid: "", // If using SendGrid, the Sendgrid API key goes here
- smtpServer: "", // If using Nodemailer, your SMTP server hostname goes here
- smtpPort: "", // If using Nodemailer, your SMTP server port goes here
- smtpUsername: "", // If using Nodemailer, your SMTP server username goes here
- smtpPassword: "", // If using Nodemailer, your SMTP password goes here
-};
diff --git a/src/config/database-docker.js b/src/config/database-docker.js
deleted file mode 100644
index 96c987d..0000000
--- a/src/config/database-docker.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- url: "mongodb://mongo:27017/gathio", // For dockerised MongoDB connection
-};
diff --git a/src/config/database-example.js b/src/config/database-example.js
deleted file mode 100644
index ca7bdcc..0000000
--- a/src/config/database-example.js
+++ /dev/null
@@ -1,3 +0,0 @@
-module.exports = {
- url: "mongodb://localhost:27017/gathio", // For local MongoDB connection
-};
diff --git a/src/config/domain-example.js b/src/config/domain-example.js
deleted file mode 100644
index abac094..0000000
--- a/src/config/domain-example.js
+++ /dev/null
@@ -1,13 +0,0 @@
-module.exports = {
- // Your domain goes here. If there is a port it should be 'domain:port', but otherwise just 'domain'
- domain: "localhost:3000",
- port: "3000",
- email: "contact@example.com",
- mailService: "nodemailer", // Which mail service to use to send emails to attendees. Options are 'nodemailer' or 'sendgrid'. Configure settings for the mail service in config/api.js.z
- sitename: "gathio",
- isFederated: true,
- // If left blank, this defaults to https://yourdomain.com/images/gathio-email-logo.gif. Set a full URL here to change it to your own logo (or just change the file itself)
- logo_url: "",
- // Show a Ko-Fi box to donate money to Raphael Kabo (Gathio's creator) on the front page
- showKofi: false,
-};
diff --git a/src/config/gathio.service b/src/config/gathio.service
deleted file mode 100644
index 447d44f..0000000
--- a/src/config/gathio.service
+++ /dev/null
@@ -1,13 +0,0 @@
-[Unit]
-Description=GathIO
-After=network.target
-
-[Service]
-Type=simple
-User=gathio
-WorkingDirectory=/srv/gathio
-ExecStart=/usr/bin/npm start
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
diff --git a/src/lib/config.ts b/src/lib/config.ts
new file mode 100644
index 0000000..d235145
--- /dev/null
+++ b/src/lib/config.ts
@@ -0,0 +1,56 @@
+import fs from "fs";
+import toml from "toml";
+
+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;
+ };
+}
+
+export const publicConfig = () => {
+ 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,
+ };
+};
+
+// 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 {
+ console.error(
+ "\x1b[31mConfiguration file not found! Have you renamed './config/config-example.toml' to './config/config.toml'?"
+ );
+ process.exit(1);
+ }
+};
+
+export default getConfig;