-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathifttt-broker.js
executable file
·54 lines (44 loc) · 1.23 KB
/
ifttt-broker.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module.exports = function (RED) {
'use strict';
var express = require('express');
var ifttt = require('ifttt');
var bodyParser = require('body-parser');
var logger = require('./ifttt-logger');
function IFTTTBrokerNode(n) {
RED.nodes.createNode(this, n);
this.expressPort = parseInt(n.port);
var node = this;
var expressApp = express();
expressApp.use(bodyParser.json());
var httpServer;
var iftttService = new ifttt({
serviceKey: this.credentials.serviceKey,
logger: logger(node)
});
this.ifttt = iftttService;
iftttService.handlers.status = function(request, callback) {
callback(null, true);
};
iftttService.addExpressRoutes(expressApp);
this.on('close', function (done) {
this.closing = true;
node.log('IFTTT broker shutting down');
if (httpServer != undefined) {
httpServer.close(function() {
done();
});
}
});
node.log('IFTTT broker listening on port ' + this.expressPort);
httpServer = expressApp.listen(this.expressPort);
}
RED.nodes.registerType(
'ifttt-broker',
IFTTTBrokerNode,
{
credentials: {
serviceKey: { type: "password" }
}
}
);
};