Use x-forwarded-for header to get ip. fallback fo clientIP

This commit is contained in:
Fred Boniface 2022-12-24 20:39:26 +00:00
parent ea43a9e371
commit deb078980b

3
app.js
View File

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