@@ -14,38 +14,55 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- // The file contains all the end points for Tracks
18-
1917var logger = require ( '_pr/logger' ) ( module ) ;
20- var request = require ( "request " ) ;
18+ var https = require ( "https " ) ;
2119var errorResponses = require ( './error_responses' ) ;
20+ var appConfig = require ( '_pr/config' ) ;
2221
2322
2423module . exports . setRoutes = function ( app , sessionVerificationFunc ) {
2524 app . all ( '/serviceAction/*' , sessionVerificationFunc ) ;
2625
2726 // Check for Service stop
2827 app . post ( '/serviceAction' , function ( req , res ) {
29-
30- console . log ( req . body ) ;
3128 var post_data = {
3229 "cmd" : req . body . cmd ,
3330 "type" : req . body . type ,
3431 "hosts" : req . body . hosts
3532 } ;
3633
37- request ( {
38- url : 'https://52.8.208.191/api/v1/webhooks/remotecmd?st2-api-key=YTU0M2RlNmMwMjdhMzFlNzVmMTExZDA4YWExMWY5MmFjOTUyYzc2Nzk5YjMzYmM4ZjAwNWJiYjc2NjFmZjY1MA' ,
39- body : post_data ,
40- method : 'post' ,
41- json : true ,
42- } , function ( err , httpResponse , body ) {
43- if ( err ) {
44- res . status ( 500 ) . send ( err ) ;
45- return ;
34+ post_data = JSON . stringify ( post_data ) ;
35+
36+
37+ var post_options = {
38+ host : appConfig . serverControllerUrl ,
39+ port : 443 ,
40+ path : '/api/v1/webhooks/remotecmd?st2-api-key=' + appConfig . serviceControllerKey ,
41+ method : 'POST' ,
42+ headers : {
43+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
44+ 'Content-Length' : Buffer . byteLength ( post_data )
4645 }
47- res . status ( 200 ) . send ( body ) ;
46+ } ;
47+
48+
49+ var post_req = https . request ( post_options , function ( httpsRes ) {
50+ httpsRes . setEncoding ( 'utf8' ) ;
51+ var data = '' ;
52+ httpsRes . on ( 'data' , function ( chunk ) {
53+ data = data + chunk
54+ console . log ( 'Response: ' + chunk ) ;
55+ } ) ;
56+ httpsRes . on ( 'end' , function ( chunk ) {
57+ res . status ( 200 ) . send ( data ) ;
58+ } ) ;
59+ httpsRes . on ( 'error' , function ( err ) {
60+ res . status ( 500 ) . send ( err ) ;
61+ } ) ;
4862 } ) ;
4963
64+ post_req . write ( post_data ) ;
65+ post_req . end ( ) ;
66+
5067 } ) ;
5168} ;
0 commit comments