From 1f7fa74c19bc1dd04aebcd33456310332b48bf4d Mon Sep 17 00:00:00 2001 From: Nathan Baker Date: Mon, 3 Dec 2018 09:52:40 -0600 Subject: [PATCH 1/2] change fork to spawn with ipc and hidden window, fixed #26 --- app/proxy.js | 38 ++++++++++++++++++++++++-------------- app/proxyWorker.js | 2 ++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/proxy.js b/app/proxy.js index b16a92a..f638e67 100644 --- a/app/proxy.js +++ b/app/proxy.js @@ -1,4 +1,4 @@ -const fork = require( 'child_process' ).fork; +const spawn = require( 'child_process' ).spawn; const path = require('path'); var proxyProcess = null; @@ -11,7 +11,7 @@ var redbirdPID = 0; var handleLogs = () => {}; function registerLogHandler( handler ) { - if( typeof handler !== 'function' ) { + if ( typeof handler !== 'function' ) { return; } handleLogs = handler; @@ -33,12 +33,12 @@ function countRequest( host, url ) { let matchedRoutes = allRoutes.filter( m => url.indexOf( m ) > -1 ); // sort by longest so best result comes first if there is more than one - if( matchedRoutes.length > 1 ) { + if ( matchedRoutes.length > 1 ) { matchedRoutes.sort( ( a, b) => b.length - a.length ); } // validadate enough results - if( matchedRoutes.length < 1 ) { + if ( matchedRoutes.length < 1 ) { return; } @@ -80,18 +80,18 @@ function findResponder( message ) { let success = message.success; matches = responderRegistry.filter( m => m.identifier === identifier ); - if( matches.length > 0 ) { + if ( matches.length > 0 ) { matches = matches[0]; - if( success ) { + if ( success ) { if ( typeof matches.success === 'function' ) { matches.success(); responderRegistry = responderRegistry.filter( m => m.identifier !== identifier ); } } - if( !success ) { + if ( !success ) { if ( typeof matches.error === 'function' ) { matches.error(); responderRegistry = responderRegistry.filter( m => m.identifier !== identifier ); @@ -107,30 +107,40 @@ function findResponder( message ) { */ function launchProxy() { return new Promise( async ( resolve, reject ) => { - proxyProcess = await fork( path.join( __dirname, 'proxyWorker.js' ), { silent: false }); + proxyProcess = await spawn( 'node', [ path.join( __dirname, 'proxyWorker.js' ) ], { + windowsHide: true, + stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ], + }); + + + if ( typeof proxyProcess.stderr !== 'undefined' && proxyProcess.stderr !== null ) { + proxyProcess.stderr.on( 'data', ( error ) => { + console.error( 'spawn error', error.toString() ); + }); + } - if (typeof proxyProcess.stdout !== 'undefined' && proxyProcess.stdout !== null ) { + if ( typeof proxyProcess.stdout !== 'undefined' && proxyProcess.stdout !== null ) { proxyProcess.stdout.on('data', data => {}) } // watch for messages proxyProcess.on( 'message', message => { - if( typeof message === 'object' ) { + if ( typeof message === 'object' ) { - if( typeof message.type !== 'undefined' && message.type === 'processReady' ) { + if ( typeof message.type !== 'undefined' && message.type === 'processReady' ) { redbirdPID = message.PID; resolve(); return; } - if( message.output ) { + if ( message.output ) { console.log( 'worker msg', message.output ); } - if( typeof message.type !== 'undefined' && message.type === 'registration_done' ) { + if ( typeof message.type !== 'undefined' && message.type === 'registration_done' ) { findResponder( message ); } - if( typeof message.type !== 'undefined' && message.type === 'unregistration_done' ) { + if ( typeof message.type !== 'undefined' && message.type === 'unregistration_done' ) { findResponder( message ); } diff --git a/app/proxyWorker.js b/app/proxyWorker.js index 7933790..a742b4d 100644 --- a/app/proxyWorker.js +++ b/app/proxyWorker.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + // listen for new messages process.on('message', async message => { From 9bdd068847955ce4b5eb298f33c8c83f78fad8a1 Mon Sep 17 00:00:00 2001 From: Nathan Baker Date: Mon, 3 Dec 2018 09:53:04 -0600 Subject: [PATCH 2/2] 1.1.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 08b6c7a..4ead256 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "red-ampp", - "version": "1.1.1", + "version": "1.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c9e0696..204596e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "red-ampp", - "version": "1.1.1", + "version": "1.1.2", "description": "developer tool for running micro services behind a redbird proxy", "main": "server.js", "scripts": {