-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
34 lines (31 loc) · 894 Bytes
/
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
/* Magic Mirror
* Module: MMM-PurpleAir
*
* author: Aaron Jones
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
const NotificationType = {
Request: "request",
Response: "response",
}
module.exports = NodeHelper.create({
start: function () {
console.log(`${this.name} helper starting...`);
},
socketNotificationReceived: function(notificationName, data) {
var that = this;
const { responseKey, req } = data
if (notificationName === `${this.name}.${NotificationType.Request}`) {
request(req, function(error, response, body) {
console.log(`${that.name} ${responseKey} response code: ${response.statusCode}`);
that.sendSocketNotification(responseKey, {
error,
request,
response
});
});
}
}
});