Skip to content

Commit

Permalink
Set unique cookie for every client
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukunin committed Mar 20, 2016
1 parent 52d91f2 commit 8abed71
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion libs/amiAlone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
var crypto = require('crypto');

module.exports = function(logger, portalConfig, poolConfigs){
var COOKIE_NAME = '_worker_id';
var ID_LENGTH = 32;

var ensureWorkerIdCookie = function(req, res) {
var cookie = req.cookies[COOKIE_NAME];
if (cookie === undefined)
{
cookie = crypto.randomBytes(ID_LENGTH).toString('hex');
res.cookie(COOKIE_NAME, cookie, {maxAge: 900000, httpOnly: true, path: '/'});
}
return cookie;
}

this.handleRequest = function(req, res, next){
res.end("Hello World");
var cookie = ensureWorkerIdCookie(req, res);
res.end("Your cookie is " + cookie);
};
};
4 changes: 4 additions & 0 deletions libs/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var redis = require('redis');
var dot = require('dot');
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var compress = require('compression');

var Stratum = require('stratum-pool');
Expand Down Expand Up @@ -231,6 +232,9 @@ module.exports = function(logger){
var app = express();


if (portalConfig.website.amiAlone.enabled) {
app.use(cookieParser());
}
app.use(bodyParser.json());

app.get('/get_page', function(req, res, next){
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"mysql": "*",
"async": "*",
"express": "*",
"cookie-parser": "*",
"body-parser": "*",
"compression": "*",
"dot": "*",
Expand Down

0 comments on commit 8abed71

Please sign in to comment.