Skip to content

Commit

Permalink
check sleep request
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil A. Siemes authored and Emil A. Siemes committed Aug 27, 2024
1 parent 9e12404 commit 306ad0b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ const axios = require("axios");
let url = require('url');
let http = require('http');
let fs = require('fs');
const dns = require('node:dns');
const os = require('node:os');

const options = { family: 4 };

let myself= "";

dns.lookup(os.hostname(), options, (err, addr) => {
if (err) {
console.error(err);
} else {
myself= addr;
}
});

let bodyParser = require('body-parser');
app = global.app = express();
Expand Down Expand Up @@ -59,6 +73,14 @@ async function sleep(ms) {
let index = require('./routes/index.js');

index.get('/sleep', async (req, res, next) => {
let client= req.headers['x-forwarded-for'];
global.logger.log("info", "Sleep request from: "+client+" I am: "+myself);
if(client!= myself && globalThis.process.env.ENV=== "PROD") {
global.logger.log("info", "Sleep request denied.");
res.status= 403;
res.send("");
return;
}
await sleep(globalThis.process.env.SLEEP);
sleepinprogress = false;
global.logger.log("info", "Woke up.");
Expand Down

0 comments on commit 306ad0b

Please sign in to comment.