11import * as zmq from "zeromq" ;
2- import {
3- ProcessedError ,
4- } from "../controllers/errorController" ;
2+ import { ProcessedError } from "../controllers/errorController" ;
53import axios from "axios" ;
4+ import { ENV_CONFIG } from "../utils/envConfig" ;
65
76const webhookUrl = "https://ping.telex.im/v1/webhooks" ;
87
@@ -11,9 +10,16 @@ async function initializeServer() {
1110 const publishSocket = new zmq . Publisher ( ) ;
1211
1312 try {
14- await replySocket . bind ( "tcp://code-error-microservice.onrender.com:3030" ) ;
15- await publishSocket . bind ( "tcp://code-error-microservice.onrender.com:3031" ) ;
16- console . log ( "ZeroMQ server bound to ports 3030 (Reply) and 3031 (Publish)" ) ;
13+ const zeroMqBindHost = "0.0.0.0" ;
14+ const zeroMqBindPortPublish = ENV_CONFIG . PORT + 1 ;
15+ const zeroMqBindPortReply = zeroMqBindPortPublish + 1 ;
16+ await replySocket . bind ( `tcp://${ zeroMqBindHost } :${ zeroMqBindPortReply } ` ) ;
17+ await publishSocket . bind (
18+ `tcp://${ zeroMqBindHost } :${ zeroMqBindPortPublish } `
19+ ) ;
20+ console . log (
21+ `ZeroMQ server bound to ports ${ zeroMqBindPortReply } (Reply) and ${ zeroMqBindPortPublish } (Publish)`
22+ ) ;
1723
1824 const serverPublish = async ( message : string ) => {
1925 await publishSocket . send ( [ "update" , message ] ) ;
@@ -29,27 +35,35 @@ async function initializeServer() {
2935 } catch ( error ) {
3036 parsedMessage = msg . toString ( ) as unknown as ProcessedError ;
3137 console . error ( "Failed to parse message:" , error ) ;
32- await replySocket . send ( JSON . stringify ( { status : "error" , message : "Invalid message format" } ) ) ;
38+ await replySocket . send (
39+ JSON . stringify ( { status : "error" , message : "Invalid message format" } )
40+ ) ;
3341 continue ;
3442 }
3543 if ( ! parsedMessage || ! parsedMessage . channelId || ! parsedMessage . errors ) {
3644 console . warn ( "Invalid message format" ) ;
37- await replySocket . send ( JSON . stringify ( { status : "error" , message : "Invalid message format" } ) ) ;
45+ await replySocket . send (
46+ JSON . stringify ( { status : "error" , message : "Invalid message format" } )
47+ ) ;
3848 continue ;
3949 }
4050
41- const errorSummary = parsedMessage . errors . map ( err => ( {
51+ const errorSummary = parsedMessage . errors . map ( ( err ) => ( {
4252 message : err . message ,
43- stack : err . stack
53+ stack : err . stack ,
4454 } ) ) ;
4555
4656 const message = `
4757 Errors:
48- ${ errorSummary . map ( ( err , index ) => `
58+ ${ errorSummary
59+ . map (
60+ ( err , index ) => `
4961 Error ${ index + 1 } :
5062 Message: ${ err . message }
5163 Stack: ${ err . stack }
52- ` ) . join ( '\n' ) }
64+ `
65+ )
66+ . join ( "\n" ) }
5367 ` . trim ( ) ;
5468
5569 const telexPayload = {
@@ -74,16 +88,20 @@ async function initializeServer() {
7488 await replySocket . send ( JSON . stringify ( { status : "success" } ) ) ;
7589 } catch ( error ) {
7690 console . error ( "Failed to send to webhook:" , error ) ;
77- await replySocket . send ( JSON . stringify ( { status : "error" , message : "Failed to send to webhook" } ) ) ;
91+ await replySocket . send (
92+ JSON . stringify ( {
93+ status : "error" ,
94+ message : "Failed to send to webhook" ,
95+ } )
96+ ) ;
7897 }
7998 }
8099
81100 return { serverPublish } ;
82101 } catch ( error ) {
83102 console . error ( "ZeroMQ server error:" , error ) ;
84103 throw error ;
85- }
86-
104+ }
87105}
88106
89- export const zeromqClient = initializeServer ( ) ;
107+ export const zeromqClient = initializeServer ( ) ;
0 commit comments