http-response-server.js
1.18 KB
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
/**
* HTTP Response Server
*
* Untuk menangkap respon dari core
*/
const module_name = require('path').basename(__filename);
const http = require('http');
const url = require('url');
const config = require('../config');
const logger = require('tektrans-logger');
let transport;
function onRequest(request, response) {
const method_name = 'onRequest';
response.end('OK');
const qs = url.parse(request.url, true).query;
logger.verbose('Got reverse report from CORE', {module_name: module_name, method_name: method_name, url: request.url, qs: qs});
if (!transport || !transport.send) {
logger.warn('UNDEFINED TRANSPORT, not forwarding message from CORE');
return;
}
if (!qs.terminal_name || !qs.message) {
return;
}
transport.send(qs.terminal_name, qs.message, qs);
}
function setTransport(newTransport) {
transport = newTransport;
}
function create() {
let listenPort = config.listen_port;
http.createServer(onRequest).listen(listenPort, function() {
logger.info('HTTP Reverse/Report server listen on port ' + listenPort + ' to process CORE message');
});
}
create();
exports.setTransport = setTransport;