Hy everyone. I am receiving /post data from bluetooth gateway. Gateway sends data (beacon MACs) x times in a second. Is this the best way to handle request? I want to save unique MACs and in some interval send data to some server.
app.post('/api', function(req, res) {
const body = req.body;
const objct = body.obj;
let gtw = body.gmac;
for (var prop in objct) {
beaconi.add(objct[prop].dmac);
}
res.set('Content-Type', 'text/plain');
res.send('Data was received');
})
setInterval(() => {
axios
.post('https://www.domain.app/beacon/api/getData.php', {
data: {
tagovi: Array.from(beaconi)
},
})
.then(res => {
console.log(`statusText: ${res.statusText}`);
console.log('BIKONI', Array.from(beaconi));
beaconi.clear();
})
}, 15000);
app.listen(8080, function(err) {
if (err) {
throw err
}
console.log('Server at 8080');
})