Commit bff86f97e7bdb5ff6cbdc09b3d17ead544c60b16
1 parent
1f789488fe
Exists in
master
config port
Showing
1 changed file
with
1 additions
and
1 deletions
Show diff stats
index.js
| 1 | const express = require('express'); | 1 | const express = require('express'); |
| 2 | const app = express(); | 2 | const app = express(); |
| 3 | const WebSocketClient = require('ws'); | 3 | const WebSocketClient = require('ws'); |
| 4 | const config = require('./config/config.json'); | 4 | const config = require('./config/config.json'); |
| 5 | 5 | ||
| 6 | app.listen(config.port); | 6 | app.listen(config.port); |
| 7 | 7 | ||
| 8 | const client = new WebSocketClient(config.urlHO); | 8 | const client = new WebSocketClient(config.urlHO); |
| 9 | 9 | ||
| 10 | client.on('open', function open() { | 10 | client.on('open', function open() { |
| 11 | console.log('conection to socket ho is open'); | 11 | console.log('conection to socket ho is open'); |
| 12 | }); | 12 | }); |
| 13 | 13 | ||
| 14 | app.get('/getSocket', function (req, res) { | 14 | app.get('/getSocket', function (req, res) { |
| 15 | 15 | ||
| 16 | var promesa = new Promise(function (resolve, reject) { | 16 | var promesa = new Promise(function (resolve, reject) { |
| 17 | 17 | ||
| 18 | client.send('isAlive?'); | 18 | client.send('isAlive?'); |
| 19 | 19 | ||
| 20 | client.on('message', function incoming(message) { | 20 | client.on('message', function incoming(message) { |
| 21 | console.log('recibe bo: %s', message); | 21 | console.log('recibe bo: %s', message); |
| 22 | resolve(message); | 22 | resolve(message); |
| 23 | }); | 23 | }); |
| 24 | }); | 24 | }); |
| 25 | 25 | ||
| 26 | promesa.then(function (data) { | 26 | promesa.then(function (data) { |
| 27 | res.send(data); | 27 | res.send(data); |
| 28 | }); | 28 | }); |
| 29 | }); | 29 | }); |
| 30 | 30 | ||
| 31 | console.log('Sevice open port 6060'); | 31 | console.log('Sevice open port ' + config.port); |
| 32 | 32 |