Update, update some stylings and much more
Took 5 minutes
This commit is contained in:
parent
09c030ea06
commit
edd48beac1
21
index.js
21
index.js
@ -31,7 +31,28 @@ const apiResponse = {
|
|||||||
data: null
|
data: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const apiRequests = { '127.0.0.1': 0 };
|
||||||
|
|
||||||
app.get( '/api/getDeviceStatus/:ipAddress', async ( req, res ) => {
|
app.get( '/api/getDeviceStatus/:ipAddress', async ( req, res ) => {
|
||||||
|
|
||||||
|
if( apiRequests[req.socket.remoteAddress] )
|
||||||
|
{
|
||||||
|
if( apiRequests[req.socket.remoteAddress] > 100 )
|
||||||
|
{
|
||||||
|
res.status( 429 );
|
||||||
|
res.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
apiRequests[req.socket.remoteAddress]++;
|
||||||
|
setTimeout( () => { apiRequests[req.socket.remoteAddress]--; }, 5000 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
apiRequests[req.socket.remoteAddress] = 1;
|
||||||
|
}
|
||||||
console.log( 'Loading device status for ' + req.params.ipAddress + '...' );
|
console.log( 'Loading device status for ' + req.params.ipAddress + '...' );
|
||||||
|
|
||||||
let ping_response = await ping.promise.probe(req.params.ipAddress, {
|
let ping_response = await ping.promise.probe(req.params.ipAddress, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user