Implemented external config provider for HA. Removed debug line

This commit is contained in:
Glenn de Haan
2024-03-23 17:33:29 +01:00
parent 186485d947
commit d147b8e5ad
3 changed files with 30 additions and 9 deletions

17
modules/config.js Normal file
View File

@@ -0,0 +1,17 @@
/**
* Import base modules
*/
const fs = require('fs');
/**
* Get an option from external config (Home Assistant)
*
* @param option
*/
module.exports = (option) => {
if (fs.existsSync('/app/options.json')) {
return JSON.parse(fs.readFileSync('/app/options.json', 'utf-8'))[option];
}
return null;
};

View File

@@ -3,16 +3,21 @@
*/
const unifi = require('node-unifi');
/**
* Import own modules
*/
const configProvider = require('./config');
/**
* Import own modules
*/
const config = {
unifi: {
ip: process.env.UNIFI_IP || '192.168.1.1',
port: process.env.UNIFI_PORT || 443,
username: process.env.UNIFI_USERNAME || 'admin',
password: process.env.UNIFI_PASSWORD || 'password',
siteID: process.env.UNIFI_SITE_ID || 'default'
ip: configProvider('unifi_ip') || process.env.UNIFI_IP || '192.168.1.1',
port: configProvider('unifi_port') || process.env.UNIFI_PORT || 443,
username: configProvider('unifi_username') || process.env.UNIFI_USERNAME || 'admin',
password: configProvider('unifi_password') || process.env.UNIFI_PASSWORD || 'password',
siteID: configProvider('unifi_site_id') || process.env.UNIFI_SITE_ID || 'default'
}
};

View File

@@ -9,6 +9,7 @@ const cookieParser = require('cookie-parser');
/**
* Import own modules
*/
const config = require('./modules/config');
const logo = require('./modules/logo');
const types = require('./modules/types');
const time = require('./modules/time');
@@ -30,7 +31,7 @@ const app = express();
* Define global functions and variables
*/
const random = (min, max) => Math.floor(Math.random() * (max - min)) + min;
const voucherTypes = types(process.env.VOUCHER_TYPES || '480,0,,,;');
const voucherTypes = types(config('voucher_types') || process.env.VOUCHER_TYPES || '480,0,,,;');
const webService = (process.env.SERVICE_WEB === 'true') || true;
const apiService = (process.env.SERVICE_API === 'true') || false;
const authDisabled = (process.env.DISABLE_AUTH === 'true') || false;
@@ -62,7 +63,7 @@ console.log(`[Auth] ${authDisabled ? 'Disabled!' : 'Enabled!'}`);
/**
* Log controller
*/
console.log(`[UniFi] Using Controller on: ${process.env.UNIFI_IP || '192.168.1.1'}:${process.env.UNIFI_PORT || 443} (Site ID: ${process.env.UNIFI_SITE_ID || 'default'})`);
console.log(`[UniFi] Using Controller on: ${config('unifi_ip') || process.env.UNIFI_IP || '192.168.1.1'}:${config('unifi_port') || process.env.UNIFI_PORT || 443} (Site ID: ${config('unifi_site_id') || process.env.UNIFI_SITE_ID || 'default'})`);
/**
* Trust proxy
@@ -118,8 +119,6 @@ app.use((req, res, next) => {
console.log(`[Web][${req.sid}]: ${req.originalUrl}`);
}
console.log(`[Web][HA Debug] ${JSON.stringify(req.headers)}`);
next();
});