make config more readable

This commit is contained in:
Holly Stubbs 2022-04-24 02:14:23 +01:00
parent b314d492a7
commit 49753398ca
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
4 changed files with 31 additions and 23 deletions

View file

@ -10,7 +10,7 @@ const app = require("express")(),
serverHandler = require("./server/serverHandler.js"), serverHandler = require("./server/serverHandler.js"),
config = require("./config.json"); config = require("./config.json");
if (config.prometheusEnabled) { if (config.prometheus.enabled) {
// We only need to require this if prom metrics are on. // We only need to require this if prom metrics are on.
const prom = require("prom-client"); const prom = require("prom-client");
@ -26,10 +26,10 @@ if (config.prometheusEnabled) {
res.end(await register.metrics()); res.end(await register.metrics());
}); });
prometheusApp.listen(config.prometheusPort, () => consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheusPort}`)); prometheusApp.listen(config.prometheus.port, () => consoleHelper.printBancho(`Prometheus metrics listening at port ${config.prometheus.port}`));
} else consoleHelper.printWarn("Prometheus is disabled!"); } else consoleHelper.printWarn("Prometheus is disabled!");
if (config.compression) { if (config.express.compression) {
app.use(require("compression")()); app.use(require("compression")());
consoleHelper.printBancho("Compression is enabled."); consoleHelper.printBancho("Compression is enabled.");
} else consoleHelper.printWarn("Compression is disabled!"); } else consoleHelper.printWarn("Compression is disabled!");
@ -76,4 +76,4 @@ app.use((req, res) => {
}); });
}); });
app.listen(config.port, () => consoleHelper.printBancho(`Binato is up! Listening at port ${config.port}`)); app.listen(config.express.port, () => consoleHelper.printBancho(`Binato is up! Listening at port ${config.express.port}`));

View file

@ -1,17 +1,25 @@
{ {
"port": 5001, "express": {
"compression": true, "port": 5001,
"prometheusEnabled": false, "compression": true
"prometheusPort": 1234, },
"redisEnabled": false, "prometheus": {
"redisAddress": "127.0.0.1", "enabled": false,
"redisPort": 6379, "port": 9100
"redisDatabase": 0, },
"redisPassword": "", "redis": {
"databaseAddress": "127.0.0.1", "enabled": false,
"databasePort": 3306, "address": "127.0.0.1",
"databaseUsername": "username", "port": 6379,
"databasePassword": "password", "password": "",
"databaseName": "osu!", "database": 0
"databaseKey": "examplekey" },
"database": {
"address": "127.0.0.1",
"port": 3306,
"username": "username",
"password": "password",
"name": "osu!",
"key": "examplekey"
}
} }

View file

@ -20,7 +20,7 @@ module.exports = {
return requiredPWChangeResponse(); return requiredPWChangeResponse();
} else { } else {
if (aes256.decrypt(config.databaseKey, userDBData.password) !== loginInfo.password) return incorrectLoginResponse(); if (aes256.decrypt(config.database.key, userDBData.password) !== loginInfo.password) return incorrectLoginResponse();
} }
return null; return null;

View file

@ -22,7 +22,7 @@ global.botUser = global.users.add("bot", new User(3, "SillyBot", "bot"));
global.botUser.location[0] = 50; global.botUser.location[0] = 50;
global.botUser.location[1] = -32; global.botUser.location[1] = -32;
global.DatabaseHelper = new DatabaseHelperClass(config.databaseAddress, config.databasePort, config.databaseUsername, config.databasePassword, config.databaseName); global.DatabaseHelper = new DatabaseHelperClass(config.database.address, config.database.port, config.database.username, config.database.password, config.database.name);
async function subscribeToChannel(channelName = "", callback = function(message) {}) { async function subscribeToChannel(channelName = "", callback = function(message) {}) {
// Dup and connect new client for channel subscription (required) // Dup and connect new client for channel subscription (required)
@ -34,11 +34,11 @@ async function subscribeToChannel(channelName = "", callback = function(message)
} }
// Do redis if it's enabled // Do redis if it's enabled
if (config.redisEnabled) { if (config.redis.enabled) {
(async () => { (async () => {
const { createClient } = require("redis"); const { createClient } = require("redis");
global.promClient = createClient({ global.promClient = createClient({
url: `redis://${config.redisPassword.replaceAll(" ", "") == "" ? "" : `${config.redisPassword}@`}${config.redisAddress}:${config.redisPort}/${config.redisDatabase}` url: `redis://${config.redis.password.replaceAll(" ", "") == "" ? "" : `${config.redis.password}@`}${config.redis.address}:${config.redis.port}/${config.redis.database}`
}); });
global.promClient.on('error', e => consoleHelper.printBancho(e)); global.promClient.on('error', e => consoleHelper.printBancho(e));