Get url of route accessed in Nodejs

Asked

Viewed 428 times

0

I need to know which external url the user accessed on my server. My script works well when the route is "localhost", but it doesn’t work to know what the url is when the domain is not the same as this one. I need that when typed "https://www.google.com" my server print on the console that the url was this.

const url = require("url");
const app = require("express")()
var privateKey  = fs.readFileSync('keys/key.key', 'utf8');
var certificate = fs.readFileSync('keys/key.cert', 'utf8');

app.use((req, res) => {
    console.log(req) //AQUI ELE SÓ MOSTRA AS ROTAS QUE COMEÇAM COM LOCALHOST
})

var serverssl = https.createServer({key: privateKey, cert: certificate}, app).listen(443);

  • 1

    A requisition http does not include data from which page the user was on before accessing your page. The only way to get some information about user activity is by tracking user cookies through services such as Google Analytics for example. If you want to know where the user is going after leaving your site, it is also not possible as the request is not sent to your server.

  • I don’t want the page he was on before, I want the page he was on at the exact moment... But I think Node is unable to give me the data of a https URL

1 answer

0

I need when typed "https://www.google.com" my print server in the console that the url was this.

It is not that Node.js who is unable to.

It is simply impossible to extract this kind of information because the request will be made to Google’s servers and not to your.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.