index.js
919 Bytes
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
const express = require('express');
const app = express();
const WebSocketClient = require('ws');
const config = require('./config/config.json');
const data = require('./data/index')(config.bo);
app.listen(config.port);
app.use(express.json({limit: '50mb'}));
const client = new WebSocketClient(config.urlHO);
client.on('open', function open() {
console.log('conection to socket ho is open');
client.send(JSON.stringify({ gln: config.gln, action: 'gln'}));
client.on('message', function incoming(message) {
message = JSON.parse(message.toString('utf8'));
switch (message.action) {
case 'getEntity':
data.getEntity(message.tableName, message.where || {}).then(function(data) {
message.data = data[0];
client.send(JSON.stringify(message));
});
break;
default:
break;
}
});
});
console.log('Sevice open port ' + config.port);