Open
Description
When communicating with other systems, sometimes we need to send the complete URL. E.g. include the full http://localhost:30000/foo?a=45
in the response when accessing that URL.
req.originURL
becomes /foo?a=45
, but the scheme and hostname parts are lost.
node.js - How to get the full URL in Express? - Stack Overflow has 578 upvotes and the top answer has 871 upvotes. But there are also a gazillion other answers of varying correctness.
The suggestion from the top answer is:
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
Could we "officialize" this and turn it into req.completeUrl()
(or whatever name you prefer) so everybody uses the same solution that works reliably? I'm happy to create a PR for this one-liner, I just wanted to ask here first...