MMM-Wordpress/node_helper.js
2023-10-09 19:21:54 +02:00

25 lines
760 B
JavaScript

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) {
console.log('Notification!');
if (notification === 'GET_POSTS') {
console.log('Notification: GET_POSTS');
const { url, posts, 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);
}
});
}
}
});