Skip to content

Commit

Permalink
Merge pull request #421 from mStirner/dev
Browse files Browse the repository at this point in the history
Fixing issues
  • Loading branch information
mStirner committed Jan 20, 2024
2 parents 3f05d5c + 502c214 commit 59c02ee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
33 changes: 31 additions & 2 deletions components/endpoints/class.endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const State = require("./class.state.js");
const Item = require("../../system/component/class.item.js");

const _expose = require("../../helper/expose.js");
const _debounce = require("../../helper/debounce.js");

/**
* @description
Expand Down Expand Up @@ -43,13 +44,41 @@ module.exports = class Endpoint extends Item {
//this.commands = new Commands(obj.commands);
//this.states = new States(obj.states);

this.states = obj.states.map((item) => {
return new State(item, async () => {
// see 407 & 420
let updater = _debounce(async () => {
try {

// trigger update on endpoint item
// otherwise ui is not rendered/refreshed on state changed
await scope.update(this._id, this);

// feedback
scope.logger.verbose("Endpoint states updated", this.states);

} catch (err) {

scope.logger.warn(err, "Could not update item states after debouncing");

}
}, 100);

// see 407 & 420
this.states = obj.states.map((item) => {
return new State(item, () => {
try {

// feedback
scope.logger.verbose(`Value in endpoint ("${obj._id}") state ("${item._id}") changed: ${item.alias}=${item.value}`);

// update item in database
//await scope.update(this._id, this);
updater();

} catch (err) {

scope.logger.warn(err, `Could not update item (${obj._id}) state ("${item._id}") in database: ${item.alias}=${item.value}`);

}
});
});

Expand Down
2 changes: 1 addition & 1 deletion routes/auth-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = (C_USERS, router) => {
return;
}

console.log("User request:", req.user, req.authenticated, process.env.API_AUTH_ENABLED, req.ip, req.socket.remoteAddress, req.method, req.url, req.headers);
//console.log("User request:", req.user, req.authenticated, process.env.API_AUTH_ENABLED, req.ip, req.socket.remoteAddress, req.method, req.url, req.headers);

next();

Expand Down
2 changes: 1 addition & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = (server) => {

// log basic http requests, do not reveal any senstive information
// thats why "req.path" is used instead of "req.url"
log.debug(`${req.socket.remoteAddress} - [${req.method}] ${req.path}`);
log.debug(`${req.ip} - [${req.method}] ${req.path}`);

// log verbose requests
// this may reveal senstive informations like tokens or cookies
Expand Down

0 comments on commit 59c02ee

Please sign in to comment.