Offer several IP Get Methods

This commit is contained in:
Fred Boniface 2022-12-24 21:30:32 +00:00
parent deb078980b
commit c15455e0d0

13
app.js
View File

@ -8,8 +8,17 @@ const instanceNumber = Math.floor(Math.random() * 101);
const app = express(); const app = express();
app.get('/', (req, res) => { app.get('/', (req, res) => {
var ip = req.headers['x-forwarded-for'] || req.ip; var xFwdIp = req.headers['x-forwarded-for'];
res.send(`node-test instance ${instanceNumber}, your IP: ${ip}`); var xRealIp = req.headers['x-real-ip'];
res.send(
{
instanceId: instanceNumber,
xForwardedFor: xFwdIp,
xRealIp: xRealIp,
requestIp: req.ip,
requestTime: Math.floor(Date.now() / 1000)
}
);
}); });
app.listen(PORT, HOST, () => { app.listen(PORT, HOST, () => {