replaced requiring config.json with a global config object

This commit is contained in:
Daniel Sommer 2022-03-24 12:50:16 +01:00
parent bc39bc1694
commit 5e6314eee9
5 changed files with 21 additions and 16 deletions

5
.vscode/launch.json vendored
View file

@ -9,7 +9,10 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/pbc.js"
"program": "${workspaceFolder}/pbc.js",
"args": [
"${workspaceFolder}/example_config.json"
]
}
]
}

View file

@ -1,20 +1,25 @@
const config = require('../config.json');
const logger = require('./logger.js');
const constants = require('./constants.js');
const timeDiff = require('./util.js').timeDiff;
const active = config.cache.active;
const lifetime = config.cache.lifetime * 60000;
let active;
let lifetime;
let modep;
const cache = new Map();
function isActive() {
if (active === undefined) {
active = global.config.cache.active;
}
return active;
}
function getLifetime() {
if (lifetime === undefined) {
lifetime = global.config.cache.lifetime * 60000
}
return lifetime;
}

View file

@ -1,4 +1,3 @@
const config = require('../config.json');
const util = require('./util.js');
const constants = require('./constants.js');
const logger = require('./logger.js');
@ -14,7 +13,7 @@ let pedalboardIdBypassOrigin;
function reset() {
return new Promise(function (resolve, reject) {
util.httpGET(config.modep.host, config.modep.port, '/reset')
util.httpGET(global.config.modep.host, global.config.modep.port, '/reset')
.then(resolve)
.catch(reject);
});
@ -35,7 +34,7 @@ function getBanks() {
// banks = util.sortById(fake);
// return resolve(fake);
util.httpGET(config.modep.host, config.modep.port, '/banks')
util.httpGET(global.config.modep.host, global.config.modep.port, '/banks')
.then(function (banks) {
for (let index = 0; index < banks.length; index++) {
let bank = banks[index];
@ -87,7 +86,7 @@ function getPedalboards() {
// pedalboards = util.sortById(fake);
// return resolve(fake);
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/list')
util.httpGET(global.config.modep.host, global.config.modep.port, '/pedalboard/list')
.then(function (pedalboards) {
let id = 1;
for (let index = 0; index < pedalboards.length; index++) {
@ -139,7 +138,7 @@ function getCurrentPedalboard() {
// .catch(reject);
// PRODUCTION
util.httpGET(config.modep.host, config.modep.port, '/pedalboard/current')
util.httpGET(global.config.modep.host, global.config.modep.port, '/pedalboard/current')
.then(getPedalboardByBundle)
.then(function (currentPedalboard) {
cache.setCurrentPedalboard(currentPedalboard);
@ -359,7 +358,7 @@ function setPedalboard(pedalboard) {
return reset()
})
.then(function () {
return util.httpPOST(config.modep.host, config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle)
return util.httpPOST(global.config.modep.host, global.config.modep.port, '/pedalboard/load_bundle/?bundlepath=' + pedalboard.bundle)
})
.then(function () {
cache.setCurrentPedalboard(pedalboard);

View file

@ -1,7 +1,6 @@
const logger = require('./logger.js');
const util = require('./util.js');
const commands = require('./commands.js');
const config = require('../config.json').osc;
const CMD = 'oscsend';
@ -16,8 +15,8 @@ async function send(controller, channel, value) {
}
logger.debug('sending value \'' + value + '\' to controller \'' + controller + '\' on channel \'' + channel + '\'...');
let args = [
config.host, config.port,
config.address,
global.config.osc.host, global.config.osc.port,
global.config.osc.address,
'm',
'00' + util.toHex(value) + '0' + util.toHex(controller) + 'b' + util.toHex(channel)
];

View file

@ -1,4 +1,3 @@
const config = require('../config.json');
const logger = require('./logger.js');
const api = require('./api.js');
const blinky = require('./blinky.js');
@ -12,8 +11,8 @@ async function start() {
if (!server) {
server = http.createServer();
}
server.listen(config.server.port, config.server.listen).on('listening', function () {
logger.debug('server listening on ' + config.server.listen + ':' + config.server.port + '...');
server.listen(global.config.server.port, global.config.server.listen).on('listening', function () {
logger.debug('server listening on ' + global.config.server.listen + ':' + global.config.server.port + '...');
blinky.setActive(true);
handleRequests();
});