changed mechanism

This commit is contained in:
2023-10-09 18:24:09 +02:00
parent 6568ffb45c
commit 26e036c71b
2 changed files with 73 additions and 50 deletions

View File

@ -0,0 +1,22 @@
const NodeHelper = require('node_helper');
const request = require('request');
module.exports = NodeHelper.create({
start: function() {
console.log('MMM-Wordpress helper started...');
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_POSTS') {
const { url, numberOfPosts } = payload;
const apiUrl = `${url}/wp-json/wp/v2/posts?per_page=${numberOfPosts}`;
request.get(apiUrl, (error, response, body) => {
if (!error && response.statusCode == 200) {
const posts = JSON.parse(body);
this.sendSocketNotification('POSTS_RESULT', posts);
}
});
}
}
});