javascript - Having problems refreshing express page -


i seem having problem getting page refresh. fill out form on html page, posts api on different service through node requestjs module. after post sent, other service conducts jobs on it's own, , use request retrive id of job done.

once have id, use launch request, getting logs job done. ofcourse logs still beeing populated @ point want function refresh webpage simple expressjs served page, , not real html, untill gets message log complete.

my main problem refresh work.

the code in main.js ( connected html page )

request({     url: 'http://'+host+'/hwchange',     method: "post",     headers: {         "content-type": "application/json",     },     body: json }) settimeout(function(){     request({         url: 'http://'+host+'/lastwf',         method: "get",     })     }, 1000) settimeout(function(){location.href='/log'}, 2000) timer = 2000 ( i=0;i<30;i++){     timer = timer+2000     settimeout(function(){         request({             url: 'http://'+host+'/log',             method: "get"         })     },timer) } 

and code in expressjs ( server side )

app.post('/hwchange', jsonparser, function (req,res) {    if (!req.body) return res.sendstatus(500)    request({       url: 'https://'+user+':'+pass+'@orcprod.adeo.no:443/vco/api/workflows/9edb9c28-2e71-4d41-a789-f7d94ee4128a/executions',       method: "post",       headers: {          "content-type": "application/json",       },       body: json.stringify(req.body)    }, function (error, response, body){          console.log(response)    }) })  app.get('/lastwf', function (req,res){    request.get('https://'+user+':'+pass+'@orcprod.adeo.no:443/vco/api/workflows/9edb9c28-2e71-4d41-a789-f7d94ee4128a/executions', function (error, response, body){       if (!error && response.statuscode == 200) {          //console.log(body)       }          var newest = json.parse(body)       newest = newest.relations.link        var arr = []       (var = newest.length - 1; >= 2; i--) {          var = newest[i].attributes[1].value          arr.push(new date(now))       }       var maxdate = new date(math.max.apply(null, arr))        (var = newest.length - 1; >= 2; i--) {          var = newest[i].attributes[1].value          if ( new date(now).gettime() == maxdate.gettime() ) {             wfid = newest[i].attributes[0].value          }       }          res.end("<br><br>all done!")    }) })           app.get('/log', function (req, res) {    request.get('https://'+user+':'+pass+'@orcprod.adeo.no:443/vco/api/workflows/9edb9c28-2e71-4d41-a789-f7d94ee4128a/executions/'+wfid+'/logs', function (error, response, body){       if (!error && response.statuscode == 200) {          //console.log(body)       }       var logs = json.parse(body)       ( = logs.logs.length -1 ; i>=0; i-- ){           res.write(logs.logs[i].entry["short-description"]+"<br>")       }       res.end("done "+wfid)    }) }) 

i've tried using location.reload in main.js, location = location.href, not seem work. think it's cause of refresh happing fast tried slow down loop.

in code i've posted here think timed refresh loop failes cause of location.href above it.

any pointers appreciated.

ended using res.render jade in order insert meta tag webpage if last message of log had not been recived. , removing meta tag if had. had desired effect. once loading /log, updates page every 2 seconds untill last log message comes along , updates stop.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -