freeCodeCamp Challenge Guide: APIs and Microservices Projects - Request Header Parser Microservice

Hints

Hint 1

Use req.headers to get the data

Hint 2

For public-ip you can use ['x-forwarded-for']

Solutions

Solution 1
app.get("/api/whoami", (req, res) => {
  const ip = req.headers['x-forwarded-for'].split(',')[0];
  const lang = req.headers["accept-language"];
  const soft = req.headers["user-agent"]
  res.json({ ipaddress: ip, language: lang, software: soft });
});