Hi i want to log https/http get requests to console.log for my glitch project
pls help
Hi i want to log https/http get requests to console.log for my glitch project
pls help
Try this:
if (location.protocol != 'https:'){
console.log("A GET request was made over http");
}else{
console.log("A GET request was made over https");
}
ok but i want to log ip adress or user-agent(browser)
For the IP you would want to look into an API.
http://www.db-ip.com
I dont want to use any third party service
I know a couple that are free. If you need them
You can look up a module called morgan, but I don’t think the glitch proxy passes on the IP, I’m not sure.
Yes, I was gonna suggest Morgan! Apparently, it can log the browser, device and IP address.
It can log anything, it’s just a middleware that prints information to stdout. It is possible to change morgan’s format and use your own where you also include protocol
, method
, ip
and more if you feel like it.
JavaScript cannot detect IP address, but Node can. Do a POST request to server, and then call
// Nodejs
res.end(req.headers["x-forwarded-for"]);
// Express
res.send(req.ip);
For user-agent, use js like
navigator.userAgent
Morgan too uses req.ip
to retrieve the remote-addr