diff options
-rw-r--r-- | .github/workflows/build-test.yaml (renamed from .github/workflows/ci.yaml) | 5 | ||||
-rwxr-xr-x | .gitignore | 4 | ||||
-rw-r--r-- | config/config.example.toml | 33 | ||||
-rw-r--r-- | package.json | 5 | ||||
-rw-r--r-- | pnpm-lock.yaml | 15 | ||||
-rw-r--r-- | src/config/api-example.js | 8 | ||||
-rw-r--r-- | src/config/database-docker.js | 3 | ||||
-rw-r--r-- | src/config/database-example.js | 3 | ||||
-rw-r--r-- | src/config/domain-example.js | 13 | ||||
-rw-r--r-- | src/config/gathio.service | 13 | ||||
-rw-r--r-- | src/lib/config.ts | 56 |
11 files changed, 101 insertions, 57 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/build-test.yaml index 882c2c9..d84282c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/build-test.yaml @@ -22,10 +22,7 @@ jobs: - name: Install dependencies run: pnpm install - name: Set up config files - run: | - cp src/config/api-example.js src/config/api.js - cp src/config/database-example.js src/config/database.js - cp src/config/domain-example.js src/config/domain.js + run: cp config/config.example.toml config/config.toml - name: Build run: pnpm build continue-on-error: true @@ -2,10 +2,8 @@ # gathio custom +config/config.toml dist -src/config/api.js -src/config/database.js -src/config/domain.js public/events/* !public/events/.gitkeep diff --git a/config/config.example.toml b/config/config.example.toml new file mode 100644 index 0000000..1ffbeb7 --- /dev/null +++ b/config/config.example.toml @@ -0,0 +1,33 @@ +[general] +# Your domain goes here. If there is a port it should be 'domain.com:port', but +# otherwise just 'domain.com'. +domain = "localhost:3000" +port = "3000" +email = "contact@example.com" +site_name = "gathio" +is_federated = 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). +email_logo_url = "" +# Show a Ko-Fi box to donate money to Raphael (Gathio's creator) on the front +# page. +show_kofi = false +# Which mail service to use to send emails to hosts and attendees. Options are +# 'nodemailer' or 'sendgrid'. Configure settings for this mail +# service below. +mail_service = "nodemailer" + +[database] +# Set up for a locally running MongoDB connection. Change this to +# 'mongodb://mongo:27017/gathio' for a Dockerised connection. +mongodb_url = "mongodb://localhost:27017/gathio" + +[nodemailer] +smtp_server = "" +smtp_port = "" +smtp_username = "" +smtp_password = "" + +[sendgrid] +api_key = "" diff --git a/package.json b/package.json index db85892..90047c3 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.3.0", "description": "", "main": "index.js", + "type": "module", "scripts": { "build": "tsc", "start": "node dist/start.js", @@ -19,7 +20,6 @@ "@sendgrid/mail": "^6.5.5", "body-parser": "^1.20.2", "cors": "^2.8.5", - "dotenv": "^6.2.0", "express": "^4.18.2", "express-fileupload": "^1.4.0", "express-handlebars": "^6.0.7", @@ -38,7 +38,8 @@ "nodemailer": "^6.9.2", "randomstring": "^1.2.3", "request": "^2.88.2", - "sanitize-html": "^2.10.0" + "sanitize-html": "^2.10.0", + "toml": "^3.0.0" }, "devDependencies": { "eslint": "^8.40.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 33b638a..e310e2f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,9 +10,6 @@ dependencies: cors: specifier: ^2.8.5 version: 2.8.5 - dotenv: - specifier: ^6.2.0 - version: 6.2.0 express: specifier: ^4.18.2 version: 4.18.2 @@ -70,6 +67,9 @@ dependencies: sanitize-html: specifier: ^2.10.0 version: 2.10.0 + toml: + specifier: ^3.0.0 + version: 3.0.0 devDependencies: eslint: @@ -1108,11 +1108,6 @@ packages: domhandler: 5.0.3 dev: false - /dotenv@6.2.0: - resolution: {integrity: sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==} - engines: {node: '>=6'} - dev: false - /ecc-jsbn@0.1.2: resolution: {integrity: sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==} dependencies: @@ -2739,6 +2734,10 @@ packages: ieee754: 1.2.1 dev: false + /toml@3.0.0: + resolution: {integrity: sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==} + dev: false + /touch@3.1.0: resolution: {integrity: sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==} hasBin: true 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; |