From 1a7fe9f6c6115f242fdc49b24fd9b2fae9afdc77 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Sat, 5 Nov 2016 12:42:58 +0100 Subject: [PATCH] fix client registration --- packages/unleash-api/lib/db/client-instances.js | 4 ++-- packages/unleash-api/lib/routes/metrics.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/unleash-api/lib/db/client-instances.js b/packages/unleash-api/lib/db/client-instances.js index b69805390b..5e050a8f37 100644 --- a/packages/unleash-api/lib/db/client-instances.js +++ b/packages/unleash-api/lib/db/client-instances.js @@ -9,9 +9,9 @@ module.exports = function (db) { return db(TABLE) .where('app_name', details.appName) .where('instance_id', details.instanceId) - .where('client_ip', details.clientIp) .update({ last_seen: 'now()', + client_ip: details.clientIp, }); } @@ -24,11 +24,11 @@ module.exports = function (db) { } function insert (details) { + console.log(details); return db(TABLE) .count('*') .where('app_name', details.appName) .where('instance_id', details.instanceId) - .where('client_ip', details.clientIp) .map(row => ({ count: row.count })) .then(rows => { if (rows[0].count > 0) { diff --git a/packages/unleash-api/lib/routes/metrics.js b/packages/unleash-api/lib/routes/metrics.js index 35640fa7b9..294ca2af8a 100644 --- a/packages/unleash-api/lib/routes/metrics.js +++ b/packages/unleash-api/lib/routes/metrics.js @@ -42,11 +42,12 @@ module.exports = function (app, config) { app.post('/client/register', (req, res) => { const data = req.body; + const clientIp = req.ip; clientStrategiesDb.insert(data.appName, data.strategies) .then(() => clientInstancesDb.insert({ appName: data.appName, instanceId: data.instanceId, - clientIp: req.ip, + clientIp, })) .then(() => console.log('new client registerd')) .catch((error) => logger.error('Error registering client', error));