@@ -36,12 +36,20 @@ const rammerheadScopes = [
3636] ;
3737const rammerheadSession = / ^ \/ [ a - z 0 - 9 ] { 32 } / ;
3838//END rammerhead specific stuff
39+ //Chalk colors for codes
40+ const error = chalk . bold . red ;
41+ const success = chalk . green ;
42+ const warning = chalk . yellow ;
43+ const info = chalk . blue ;
44+ const debug = chalk . magenta ;
45+ const boldInfo = chalk . bold . blue ;
46+ const debug2 = chalk . cyan ;
47+ //END CHALK
3948dotenv . config ( ) ;
4049//getting environment vars
4150const numCPUs = process . env . CPUS || os . cpus ( ) . length ;
4251let key = process . env . KEY || 'unlock' ;
4352let uri = process . env . URL || 'rubynetwork.tech' ;
44- let start = false ;
4553if ( uri . includes ( 'http' ) ) {
4654 uri = uri . replace ( 'http://' , '' ) ;
4755}
@@ -64,18 +72,17 @@ fs.readFile(join(__dirname, 'blocklists/ADS.txt'), (err, data) => {
6472 for ( let i in lines ) blacklisted . push ( lines [ i ] ) ;
6573} ) ;
6674if ( numCPUs > 0 && cluster . isPrimary ) {
67- console . log ( chalk . cyan ( chalk . bold ( 'Starting Server...' ) ) )
68- console . log ( chalk . yellow ( `Primary ${ process . pid } is running` ) ) ;
75+ console . log ( debug ( `Primary ${ process . pid } is running` ) ) ;
6976 for ( let i = 0 ; i < numCPUs ; i ++ ) {
7077 cluster . fork ( ) . on ( 'online' , ( ) => {
71- console . log ( chalk . magenta ( `Worker ${ i + 1 } is online` ) ) ;
78+ console . log ( debug2 ( `Worker ${ i + 1 } is online` ) ) ;
7279 } ) ;
7380 }
7481 cluster . on ( 'exit' , ( worker , code , signal ) => {
75- console . log ( chalk . red ( chalk . bold (
82+ console . log ( error (
7683 `Worker ${ worker . process . pid } died with code: ${ code } and signal: ${ signal } `
77- ) ) ) ;
78- console . log ( chalk . yellow ( `Starting new worker in it's place` ) ) ;
84+ ) ) ;
85+ console . log ( warning ( `Starting new worker in it's place` ) ) ;
7986 cluster . fork ( ) ;
8087 } ) ;
8188} else {
@@ -113,7 +120,7 @@ if (numCPUs > 0 && cluster.isPrimary) {
113120 return ;
114121 }
115122 } else if ( shouldRouteRh ( req ) ) {
116- routeRhRequest ( req , res ) ;
123+ routeRhRequest ( req , res ) ;
117124 //@ts -ignore
118125 } else if ( req . headers . host === uri ) {
119126 app ( req , res ) ;
@@ -156,7 +163,10 @@ if (numCPUs > 0 && cluster.isPrimary) {
156163 bare . routeUpgrade ( req , socket , head ) ;
157164 }
158165 else if ( shouldRouteRh ( req ) ) {
159- routeRhUpgrade ( req , socket , head ) ;
166+ try {
167+ routeRhUpgrade ( req , socket , head ) ;
168+ }
169+ catch ( error ) { }
160170 }
161171 else {
162172 socket . end ( ) ;
@@ -250,7 +260,6 @@ if (numCPUs > 0 && cluster.isPrimary) {
250260 res . end ( ) ;
251261 return ;
252262 } ) ;
253-
254263 //!CUSTOM ENDPOINTS END
255264 //RAMMERHEAD FUNCTIONS
256265 //@ts -ignore
@@ -267,7 +276,10 @@ if (numCPUs > 0 && cluster.isPrimary) {
267276 }
268277 //@ts -ignore
269278 function routeRhUpgrade ( req , socket , head ) {
270- rh . emit ( 'upgrade' , req , socket , head ) ;
279+ try {
280+ rh . emit ( 'upgrade' , req , socket , head ) ;
281+ }
282+ catch ( error ) { }
271283 }
272284//END RAMMERHEAD SPECIFIC FUNCTIONS
273285 let port = parseInt ( process . env . PORT || '' ) ;
@@ -280,13 +292,13 @@ if (numCPUs > 0 && cluster.isPrimary) {
280292 // by default we are listening on 0.0.0.0 (every interface)
281293 // we just need to list a few
282294 // LIST PID
283- console . log ( chalk . green ( `Process id: ${ process . pid } ` ) ) ;
284- console . log ( chalk . blue ( 'Listening on:' ) ) ;
295+ console . log ( success ( `Process id: ${ process . pid } ` ) ) ;
296+ console . log ( debug ( 'Listening on:' ) ) ;
285297 //@ts -ignore
286- console . log ( chalk . blue ( `\thttp://localhost:${ address . port } ` ) ) ;
298+ console . log ( debug2 ( `\thttp://localhost:${ address . port } ` ) ) ;
287299 //@ts -ignore
288- console . log ( chalk . blue ( `\thttp://${ hostname ( ) } :${ address . port } ` ) ) ;
289- console . log ( chalk . blue (
300+ console . log ( debug2 ( `\thttp://${ hostname ( ) } :${ address . port } ` ) ) ;
301+ console . log ( debug2 (
290302 `\thttp://${
291303 //@ts -ignore
292304 address . family === 'IPv6'
0 commit comments