I have been following similar procedures taught by this youtuber from freeCodeCamp: https://www.youtube.com/playlist?list=PLtwj5TTsiP7vmgyFgrwtPxybl9KzMvmAB
I first use Mac terminal and sublime text 3 to use npm and code, then I deploy to heroku.
var express = require("express"); var router = express.Router(); var requestIP = require("request-ip")
/* GET home page. */ router.get('/', function(req, res) {
var language = req.headers['accept-language'].split(",")[0] var software = req.headers['user-agent'].match(/\((.+?)\)/)[1] var ip = requestIP.getClientIp(req)
var result = {'ipaddress' : req.ip ,'Language' : language, 'software': software };
res.json(result); console.log(JSON.stringify(req.headers));
}); module.exports = router;
I was able to extract software detail and language property from the request header, but I just couldn’t extract the IP address at all.
Both req.ip and request-ip module and its method doesnt return a correctly formatted ip-address. It shows something like this:
“ipaddress”:“::ffff:10.178.64.67”
Please advise, any kind souls?
This is the url of my project in heroku: https://dariusheaderparser.herokuapp.com/
This is the github repo of my project: GitHub - hesingon/FreeCodeCamp-header-parser: 2nd api project
