Reputation: 3472
I am building an Express App and I need to store the user's URL from where their AJAX request was made. For example, if I have a website at www.example.com make an HTTP request to my Express App on Heroku, I want to get the www.example.com URL. I used this code below from another SO article and it is returning the host name of my Heroku app.
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
Also tried this:
var fullUrl = req.protocol + '://' + req.hostname + req.originalUrl;
The get('host') and hostname are the parts that are rendering incorrectly. Again, I want to get the URL from where the HTTP request came from.
Thanks,
Upvotes: 1
Views: 624
Reputation: 36541
I think what you are looking for is the Referrer
var fullUrl = req.get('Referrer');
Upvotes: 2