Commit 4ab15cf3ab581ef65d118b07f3ad5bd752c9b43f
1 parent
ef7e56a5
Exists in
master
and in
1 other branch
Refactoring the source code of endpoints files
Showing
2 changed files
with
42 additions
and
6 deletions
Show diff stats
endpoints/video.js
| @@ -54,7 +54,7 @@ function init(req, res) { | @@ -54,7 +54,7 @@ function init(req, res) { | ||
| 54 | /* Listener que dispara quando a requisição ao core finaliza */ | 54 | /* Listener que dispara quando a requisição ao core finaliza */ |
| 55 | child.on('close', function(code, signal){ | 55 | child.on('close', function(code, signal){ |
| 56 | if (code !== 0) { | 56 | if (code !== 0) { |
| 57 | - { console.log(error); res.send(500, { 'error': 'Erro no Core', 'code': code }); return; } | 57 | + console.log('Erro código: ' + code); res.send(500, { 'error': 'Erro no Core', 'code': code }); return; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + properties.ID_FROM_BD + '.flv' }); | 60 | res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + properties.ID_FROM_BD + '.flv' }); |
| @@ -68,7 +68,25 @@ function init(req, res) { | @@ -68,7 +68,25 @@ function init(req, res) { | ||
| 68 | 68 | ||
| 69 | child.on('close', function(code, signal){ | 69 | child.on('close', function(code, signal){ |
| 70 | if (code !== 0) { | 70 | if (code !== 0) { |
| 71 | - { console.log(error); res.send(500, { 'error': 'Erro no Core', 'code': code }); return; } | 71 | + var data = querystring.stringify( { 'error': 'Erro no Core', 'code': code } ); |
| 72 | + | ||
| 73 | + var options = { | ||
| 74 | + host: path.hostname, | ||
| 75 | + port: path.port, | ||
| 76 | + path: path.path, | ||
| 77 | + method: 'POST', | ||
| 78 | + headers: { | ||
| 79 | + 'Content-Type': 'application/x-www-form-urlencoded', | ||
| 80 | + 'Content-Length': Buffer.byteLength(data) | ||
| 81 | + } | ||
| 82 | + }; | ||
| 83 | + | ||
| 84 | + var requesting = http.request(options, function(res) { | ||
| 85 | + res.setEncoding('utf8'); | ||
| 86 | + }); | ||
| 87 | + | ||
| 88 | + requesting.write(data); | ||
| 89 | + requesting.end(); | ||
| 72 | } | 90 | } |
| 73 | 91 | ||
| 74 | var path = url.parse(req.body.callback); | 92 | var path = url.parse(req.body.callback); |
| @@ -102,7 +120,7 @@ function init(req, res) { | @@ -102,7 +120,7 @@ function init(req, res) { | ||
| 102 | /* Listener que dispara quando a requisição ao core da erro */ | 120 | /* Listener que dispara quando a requisição ao core da erro */ |
| 103 | child.on('error', function(code, signal){ | 121 | child.on('error', function(code, signal){ |
| 104 | 122 | ||
| 105 | - var data = querystring.stringify(parameters.errorMessage('Erro na chamada ao core')); | 123 | + var data = querystring.stringify( { 'error': 'Erro na chamada ao Core', 'code': code } ); |
| 106 | 124 | ||
| 107 | var options = { | 125 | var options = { |
| 108 | host: path.hostname, | 126 | host: path.hostname, |
endpoints/video_legenda.js
| @@ -66,7 +66,7 @@ function init(req, res) { | @@ -66,7 +66,7 @@ function init(req, res) { | ||
| 66 | /* Listener que dispara quando a requisição ao core finaliza */ | 66 | /* Listener que dispara quando a requisição ao core finaliza */ |
| 67 | child.on('close', function(code, signal){ | 67 | child.on('close', function(code, signal){ |
| 68 | if (code !== 0) { | 68 | if (code !== 0) { |
| 69 | - { console.log(error); res.send(500, { 'error': 'Erro no Core', 'code': code }); return; } | 69 | + console.log('Erro código: ' + code); res.send(500, { 'error': 'Erro no Core', 'code': code }); return; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + properties.ID_FROM_BD + '.flv' }); | 72 | res.send(200, { 'response' : 'http://' + properties.SERVER_IP + ':' + properties.port + '/' + properties.ID_FROM_BD + '.flv' }); |
| @@ -80,7 +80,25 @@ function init(req, res) { | @@ -80,7 +80,25 @@ function init(req, res) { | ||
| 80 | 80 | ||
| 81 | child.on('close', function(code, signal){ | 81 | child.on('close', function(code, signal){ |
| 82 | if (code !== 0) { | 82 | if (code !== 0) { |
| 83 | - { console.log(error); res.send(500, { 'error': 'Erro no Core', 'code': code }); return; } | 83 | + var data = querystring.stringify( { 'error': 'Erro no Core', 'code': code } ); |
| 84 | + | ||
| 85 | + var options = { | ||
| 86 | + host: path.hostname, | ||
| 87 | + port: path.port, | ||
| 88 | + path: path.path, | ||
| 89 | + method: 'POST', | ||
| 90 | + headers: { | ||
| 91 | + 'Content-Type': 'application/x-www-form-urlencoded', | ||
| 92 | + 'Content-Length': Buffer.byteLength(data) | ||
| 93 | + } | ||
| 94 | + }; | ||
| 95 | + | ||
| 96 | + var requesting = http.request(options, function(res) { | ||
| 97 | + res.setEncoding('utf8'); | ||
| 98 | + }); | ||
| 99 | + | ||
| 100 | + requesting.write(data); | ||
| 101 | + requesting.end(); | ||
| 84 | } | 102 | } |
| 85 | 103 | ||
| 86 | var path = url.parse(req.body.callback); | 104 | var path = url.parse(req.body.callback); |
| @@ -114,7 +132,7 @@ function init(req, res) { | @@ -114,7 +132,7 @@ function init(req, res) { | ||
| 114 | /* Listener que dispara quando a requisição ao core da erro */ | 132 | /* Listener que dispara quando a requisição ao core da erro */ |
| 115 | child.on('error', function(code, signal){ | 133 | child.on('error', function(code, signal){ |
| 116 | 134 | ||
| 117 | - var data = querystring.stringify(parameters.errorMessage('Erro na chamada ao core')); | 135 | + var data = querystring.stringify( { 'error': 'Erro na chamada ao Core', 'code': code } ); |
| 118 | 136 | ||
| 119 | var options = { | 137 | var options = { |
| 120 | host: path.hostname, | 138 | host: path.hostname, |