-
Notifications
You must be signed in to change notification settings - Fork 6
/
api.js
executable file
·32 lines (27 loc) · 1005 Bytes
/
api.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
var request = require('request');
var NODE_PATH = '/wirenboard/';
module.exports = function(RED) {
RED.httpAdmin.get(NODE_PATH + 'static/*', function (req, res) {
var options = {
root: __dirname + '/static/',
dotfiles: 'deny'
};
res.sendFile(req.params[0], options);
});
RED.httpAdmin.get(NODE_PATH + 'getChannels', function (req, res) {
var config = req.query;
var controller = RED.nodes.getNode(config.controllerID);
var forceRefresh = config.forceRefresh ? ['1', 'yes', 'true'].includes(config.forceRefresh.toLowerCase()) : false;
if (controller && controller.constructor.name === "ServerNode") {
controller.getChannels(function (items) {
if (items) {
res.json(items);
} else {
res.status(404).end();
}
}, forceRefresh);
} else {
res.status(404).end();
}
});
}