make config more readable
This commit is contained in:
parent
b314d492a7
commit
49753398ca
4 changed files with 31 additions and 23 deletions
|
@ -10,7 +10,7 @@ const app = require("express")(),
|
|||
serverHandler = require("./server/serverHandler.js"),
|
||||
config = require("./config.json");
|
||||
|
||||
if (config.prometheusEnabled) {
|
||||
if (config.prometheus.enabled) {
|
||||
// We only need to require this if prom metrics are on.
|
||||
const prom = require("prom-client");
|
||||
|
||||
|
@ -26,10 +26,10 @@ if (config.prometheusEnabled) {
|
|||
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!");
|
||||
|
||||
if (config.compression) {
|
||||
if (config.express.compression) {
|
||||
app.use(require("compression")());
|
||||
consoleHelper.printBancho("Compression is enabled.");
|
||||
} 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}`));
|
|
@ -1,17 +1,25 @@
|
|||
{
|
||||
"port": 5001,
|
||||
"compression": true,
|
||||
"prometheusEnabled": false,
|
||||
"prometheusPort": 1234,
|
||||
"redisEnabled": false,
|
||||
"redisAddress": "127.0.0.1",
|
||||
"redisPort": 6379,
|
||||
"redisDatabase": 0,
|
||||
"redisPassword": "",
|
||||
"databaseAddress": "127.0.0.1",
|
||||
"databasePort": 3306,
|
||||
"databaseUsername": "username",
|
||||
"databasePassword": "password",
|
||||
"databaseName": "osu!",
|
||||
"databaseKey": "examplekey"
|
||||
"express": {
|
||||
"port": 5001,
|
||||
"compression": true
|
||||
},
|
||||
"prometheus": {
|
||||
"enabled": false,
|
||||
"port": 9100
|
||||
},
|
||||
"redis": {
|
||||
"enabled": false,
|
||||
"address": "127.0.0.1",
|
||||
"port": 6379,
|
||||
"password": "",
|
||||
"database": 0
|
||||
},
|
||||
"database": {
|
||||
"address": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"username": "username",
|
||||
"password": "password",
|
||||
"name": "osu!",
|
||||
"key": "examplekey"
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ module.exports = {
|
|||
|
||||
return requiredPWChangeResponse();
|
||||
} 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;
|
||||
|
|
|
@ -22,7 +22,7 @@ global.botUser = global.users.add("bot", new User(3, "SillyBot", "bot"));
|
|||
global.botUser.location[0] = 50;
|
||||
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) {}) {
|
||||
// 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
|
||||
if (config.redisEnabled) {
|
||||
if (config.redis.enabled) {
|
||||
(async () => {
|
||||
const { createClient } = require("redis");
|
||||
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));
|
||||
|
|
Loading…
Reference in a new issue