@@ -7,6 +7,26 @@ const exec = require('child_process').exec;
77var http = require ( 'http' ) ;
88var dispatcher = require ( 'httpdispatcher' ) ;
99
10+ // this query is used to check if ROS has started
11+ // while waiting for a permanante fix in https://github.com/realm/realm-object-server/issues/1297.
12+ // query should return 200 with the JSON payload Ex: {"version":"1.8.1","flavor":"developer","setupRequired":true}
13+ var options = {
14+ hostname : '127.0.0.1' ,
15+ port : 9080 ,
16+ path : '/api/info' ,
17+ method : 'GET'
18+ } ;
19+
20+ function tryUntilROSStart ( options , callback ) {
21+ var req = http . request ( options , function ( res ) {
22+ callback ( null , res ) ;
23+ } ) ;
24+ req . on ( 'error' , function ( e ) {
25+ tryUntilROSStart ( options , callback ) ;
26+ } ) ;
27+ req . end ( ) ;
28+ }
29+
1030// Automatically track and cleanup files at exit
1131temp . track ( ) ;
1232
@@ -34,12 +54,6 @@ function handleRequest(request, response) {
3454var syncServerChildProcess = null ;
3555
3656function startRealmObjectServer ( done ) {
37- // Hack for checking the ROS is fully initialized.
38- // Consider the ROS is initialized fully only if log below shows twice
39- // "client: Closing Realm file: /tmp/ros117521-7-1eiqt7a/internal_data/permission/__auth.realm"
40- // https://github.com/realm/realm-object-server/issues/1297
41- var logFindingCounter = 2
42-
4357 stopRealmObjectServer ( function ( err ) {
4458 if ( err ) {
4559 return ;
@@ -56,12 +70,6 @@ function startRealmObjectServer(done) {
5670 { env : env , cwd : path } ) ;
5771 // local config:
5872 syncServerChildProcess . stdout . on ( 'data' , ( data ) => {
59- if ( logFindingCounter != 0 && / c l i e n t : C l o s i n g R e a l m f i l e : .* _ _ a u t h .r e a l m / . test ( data ) ) {
60- if ( logFindingCounter == 1 ) {
61- done ( )
62- }
63- logFindingCounter --
64- }
6573 winston . info ( `stdout: ${ data } ` ) ;
6674 } ) ;
6775
@@ -72,6 +80,11 @@ function startRealmObjectServer(done) {
7280 syncServerChildProcess . on ( 'close' , ( code ) => {
7381 winston . info ( `child process exited with code ${ code } ` ) ;
7482 } ) ;
83+
84+ tryUntilROSStart ( options , function ( err , resp ) {
85+ winston . info ( '>>>>>>>>>>>>>>>>>>> [ROS] server started <<<<<<<<<<<<<<<<<<<' ) ;
86+ done ( )
87+ } ) ;
7588 }
7689 } ) ;
7790 } ) ;
@@ -94,7 +107,7 @@ function stopRealmObjectServer(callback) {
94107dispatcher . onGet ( "/start" , function ( req , res ) {
95108 startRealmObjectServer ( ( ) => {
96109 res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
97- res . end ( 'Starting a server ' ) ;
110+ res . end ( 'Server started ' ) ;
98111 } )
99112} ) ;
100113
0 commit comments