javascript - Nodejs is reloading app.get every 2 minute -


i using node.js first time , have problem because refreshing 1 of methods( app.get('/addtohistory') every 2 minutes without iteraction side or browser. problem somewhere in server.js configuration cannot found it.

i trying build spa angularjs, nodejs , mysql. there 3 pages: home page (with images), image page (user can click on image home page see details image) , history (all images user saw). there wouldn't login functionality. app recognizing user session id, saved db.

i using routing of angular navigate between different pages.

here configuration of server.js

var mysql = require('mysql'); var cookieparser = require('cookie-parser'); var express = require('express'); var app = module.exports = express(); var session = require('express-session'); var mysqlstore = require('express-mysql-session')(session);  app.use(cookieparser());  var db_options = {     host: 'localhost',     //port: 3306,     user: 'user',     password: 'password',     database: 'mydb' };  var option = {     host: 'localhost',     //port: 3306,     user: 'user',     password: 'password',     database: 'mydb',     schema: {         tablename: 'sessions',         columnnames: {             sessions_id: 'sessions_id',             expires: 'expires',             data: 'data'         }     } };  var method = db.prototype;  function db() {     var con = mysql.createpool(db_options);     this.connection = con; }  method.getcon = function () {     return this; };  module.exports = db; var connection_object = new db(); var db_connection = connection_object.connection;  app.get('/load', function (req, res) {     console.log('load');     db_connection.query("select * sessions", function (err, rows) {         if (err) {             console.log("problem mysql" + err);         }         else {             res.end(json.stringify(rows));         }     }); });  app.get('/addtohistory', function (req, res) {     //this method recalling every 2 minutes     console.log('addtohistory');     var imageid = req.query.imageid;     var sessionid = req.cookies['image-session'];     sessionid = sessionid.substring(sessionid.indexof(':') + 1, sessionid.indexof('.'));     checkifexist();      function checkifexist(){         db_connection.query('select * `history` `session_id`="'+sessionid+'" , `image_id`="'+imageid+'"', function (error, rows) {             if (error) {                 console.log('problem mysql' + error);             }else{                 if(rows.length >= 1){                     updateexisting();                 }else{                     createnew();                 }             }         })     }      function createnew() {         db_connection.query('insert `history` (`session_id`, `image_id`) values ("' + sessionid + '", "' + imageid + '")', function (error, rows) {             if (error) {                 console.log('problem mysql' + error);             }else{              }         })     }      function updateexisting(){         db_connection.query('update history set created=now() `session_id`="'+sessionid+'" , `image_id`="'+imageid+'"', function(error, rows){             if (error) {                 console.log('problem mysql' + error);             }else{              }         })     }  });  var connection = mysql.createconnection(db_options); var sessionstore = new mysqlstore(option, connection);  app.use(session({     name: 'image-session',     secret: 'thisidasnkjcmsxhodsjafasd89fdashojnva',     cookie: {maxage: 365 * 24 * 60 * 60 * 1000, httponly: false, secure: false},     resave: true,     saveuninitialized: true,     store: sessionstore }));  app.use('/js', express.static(__dirname + '/app/js')); app.use('/bower_components', express.static(__dirname + '/app/bower_components')); app.use('/css', express.static(__dirname + '/app/css')); app.use('/partials', express.static(__dirname + '/app/partials')); app.use('/views', express.static(__dirname + '/app/views')); app.use('/components', express.static(__dirname + '/app/components')); app.use('/images', express.static(__dirname + '/app/images'));  app.use(function (req, res) {     console.log(req.session.id)     res.sendfile(__dirname + '/app/index.html') });  app.listen(process.env.port || 8080, function () {     console.log("server listening "); }); 

when user click on of images opening new page (state) controller calling factory function. here factory:

app.factory('dbcommunication', ['$http', function ($http) {      var obj = {};      obj.addtohistory = function(image){         console.log('call');         $http.get('http://localhost:8080/addtohistory?imageid='+image.id).success(function(data){         })          return;     }      return obj;  }]); 

any idea why node.js reloading app.get('/addtohistory' every 2 minutes?

btw. ask think server.js configuration. ok? should change in it? not sure if idea keep sessionid cookie.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -