mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
fix client registration
This commit is contained in:
parent
167d1a8908
commit
1a7fe9f6c6
@ -9,9 +9,9 @@ module.exports = function (db) {
|
|||||||
return db(TABLE)
|
return db(TABLE)
|
||||||
.where('app_name', details.appName)
|
.where('app_name', details.appName)
|
||||||
.where('instance_id', details.instanceId)
|
.where('instance_id', details.instanceId)
|
||||||
.where('client_ip', details.clientIp)
|
|
||||||
.update({
|
.update({
|
||||||
last_seen: 'now()',
|
last_seen: 'now()',
|
||||||
|
client_ip: details.clientIp,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,11 +24,11 @@ module.exports = function (db) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function insert (details) {
|
function insert (details) {
|
||||||
|
console.log(details);
|
||||||
return db(TABLE)
|
return db(TABLE)
|
||||||
.count('*')
|
.count('*')
|
||||||
.where('app_name', details.appName)
|
.where('app_name', details.appName)
|
||||||
.where('instance_id', details.instanceId)
|
.where('instance_id', details.instanceId)
|
||||||
.where('client_ip', details.clientIp)
|
|
||||||
.map(row => ({ count: row.count }))
|
.map(row => ({ count: row.count }))
|
||||||
.then(rows => {
|
.then(rows => {
|
||||||
if (rows[0].count > 0) {
|
if (rows[0].count > 0) {
|
||||||
|
@ -42,11 +42,12 @@ module.exports = function (app, config) {
|
|||||||
|
|
||||||
app.post('/client/register', (req, res) => {
|
app.post('/client/register', (req, res) => {
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
|
const clientIp = req.ip;
|
||||||
clientStrategiesDb.insert(data.appName, data.strategies)
|
clientStrategiesDb.insert(data.appName, data.strategies)
|
||||||
.then(() => clientInstancesDb.insert({
|
.then(() => clientInstancesDb.insert({
|
||||||
appName: data.appName,
|
appName: data.appName,
|
||||||
instanceId: data.instanceId,
|
instanceId: data.instanceId,
|
||||||
clientIp: req.ip,
|
clientIp,
|
||||||
}))
|
}))
|
||||||
.then(() => console.log('new client registerd'))
|
.then(() => console.log('new client registerd'))
|
||||||
.catch((error) => logger.error('Error registering client', error));
|
.catch((error) => logger.error('Error registering client', error));
|
||||||
|
Loading…
Reference in New Issue
Block a user