-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnode_helper.js
34 lines (32 loc) · 1 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* MagicMirror²
* Module: MMM-Rest
*
* By Dirk Melchers
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log(this.name + ' helper started ...');
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'MMM_REST_REQUEST') {
var that = this;
request({
url: payload.url,
method: 'GET'
}, function(error, response, body) {
// console.log("MMM_REST response:");
if (!error && response.statusCode == 200) {
// console.log("send notification: "+payload.id);
that.sendSocketNotification('MMM_REST_RESPONSE', {
id: payload.id,
data: response,
tableID: payload.tableID
});
}
});
}
}
});