StormChanger StormChanger - 5 months ago 8
Node.js Question

How to implement Evercookie in sails.js/node.js?

I followed the link as


https://github.com/truongsinh/node-evercookie


First created a middleware for connect in config/http.js

and then followed the link :


http://samy.pl/evercookie/


Results In chrome Console :

Storage mechanism userData returned: undefined<br>
Storage mechanism cookieData returned: undefined<br>
Storage mechanism localData returned: 12345<br>
Storage mechanism globalData returned: undefined<br>
Storage mechanism sessionData returned: 12345<br>
Storage mechanism windowData returned: 12345<br>
Storage mechanism historyData returned: undefined<br>
Storage mechanism pngData returned: undefined<br>
Storage mechanism etagData returned: <br>
Storage mechanism cacheData returned: <br>
Storage mechanism dbData returned: 12345<br>
Storage mechanism lsoData returned: undefined<br>
Storage mechanism slData returned: undefined<br>


At front end Java script it is giving the correct id in alert as I set.

At Server Side : I get the cookieValue= undefined

Kindle help me whether this is the right way or I am missing anything in between.

Answer

I tried a lot then used evercookie.js file from the website "http://samy.pl/evercookie/" itself.

then make changes in http middleware given as follows :

var evercookie = require('evercookie');
    var cookieParser = require('cookie-parser');
    app.use(cookieParser());
    app.use(evercookie.backend());
    app.use(cookieParser());
    app.use(require('connect').static(__dirname +'../public')); // be careful, you may want to use path.join instead!
    app.use(evercookie.backend({
      pngCookieName: 'evercookie_png',
      etagCookieName: 'evercookie_etag',
      cacheCookieName: 'evercookie_cache',
      pngPath: '/path/evercookie_png.php',
      etagPath: '/path/evercookie_etag.php',
      cachePath: '/path/evercookie_cache.php'
    }));

Note: 'path' is a location from where ec.set and ec.get method is called. Now I am able to get cookie data for etagData, cacheData and cacheData.