mirror of https://github.com/Lissy93/dashy.git
Make userHeader pull from config
This commit is contained in:
parent
4aa34f66dc
commit
27dfe6219a
|
@ -18,7 +18,8 @@ const history = require('connect-history-api-fallback');
|
||||||
|
|
||||||
/* Kick of some basic checks */
|
/* Kick of some basic checks */
|
||||||
require('./services/update-checker'); // Checks if there are any updates available, prints message
|
require('./services/update-checker'); // Checks if there are any updates available, prints message
|
||||||
require('./services/config-validator'); // Include and kicks off the config file validation script
|
let config = {}; // setup the config
|
||||||
|
config = require('./services/config-validator'); // Include and kicks off the config file validation script
|
||||||
|
|
||||||
/* Include route handlers for API endpoints */
|
/* Include route handlers for API endpoints */
|
||||||
const statusCheck = require('./services/status-check'); // Used by the status check feature, uses GET
|
const statusCheck = require('./services/status-check'); // Used by the status check feature, uses GET
|
||||||
|
@ -94,6 +95,7 @@ const app = express()
|
||||||
.use(ENDPOINTS.save, method('POST', (req, res) => {
|
.use(ENDPOINTS.save, method('POST', (req, res) => {
|
||||||
try {
|
try {
|
||||||
saveConfig(req.body, (results) => { res.end(results); });
|
saveConfig(req.body, (results) => { res.end(results); });
|
||||||
|
config = req.body.config; // update the config
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
printWarning('Error writing config file to disk', e);
|
printWarning('Error writing config file to disk', e);
|
||||||
res.end(JSON.stringify({ success: false, message: e }));
|
res.end(JSON.stringify({ success: false, message: e }));
|
||||||
|
@ -128,7 +130,7 @@ const app = express()
|
||||||
// GET endpoint to return user info
|
// GET endpoint to return user info
|
||||||
.use(ENDPOINTS.getUser, (req, res) => {
|
.use(ENDPOINTS.getUser, (req, res) => {
|
||||||
try {
|
try {
|
||||||
const user = getUser(req);
|
const user = getUser(config, req);
|
||||||
res.end(JSON.stringify(user));
|
res.end(JSON.stringify(user));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.end(JSON.stringify({ success: false, message: e }));
|
res.end(JSON.stringify({ success: false, message: e }));
|
||||||
|
|
|
@ -99,10 +99,11 @@ const printFileReadError = (e) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
try { // Try to open and parse the YAML file
|
try { // Try to open and parse the YAML file
|
||||||
const config = yaml.load(fs.readFileSync('./public/conf.yml', 'utf8'));
|
config = yaml.load(fs.readFileSync('./public/conf.yml', 'utf8'));
|
||||||
validate(config);
|
validate(config);
|
||||||
} catch (e) { // Something went very wrong...
|
} catch (e) { // Something went very wrong...
|
||||||
setIsValidVariable(false);
|
setIsValidVariable(false);
|
||||||
logToConsole(bigError());
|
logToConsole(bigError());
|
||||||
printFileReadError(e);
|
printFileReadError(e);
|
||||||
}
|
}
|
||||||
|
module.exports = config;
|
|
@ -1,5 +1,11 @@
|
||||||
module.exports = (req) => {
|
module.exports = (config, req) => {
|
||||||
const userHeader = "Remote-User";
|
try {
|
||||||
console.log("Running Server Side", req.headers[userHeader.toLowerCase()]); // eslint-disable-line no-console
|
if ( config.appConfig.auth.enableHeaderAuth ) {
|
||||||
return { "success": true, "user": req.headers[userHeader.toLowerCase()] };
|
const userHeader = config.appConfig.auth.headerAuth.userHeader;
|
||||||
|
return { "success": true, "user": req.headers[userHeader.toLowerCase()] };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Error get-user: ", e);
|
||||||
|
return { 'success': false };
|
||||||
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue