Request: Introduce a `req.completeURL()` method
- Dominant language
- JavaScript
- Stars
- 69.5k
- Forks
- 25k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 9
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](https://stackoverflow.com/questions/10183291/how-to-get-the-full-url-in-express) 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](https://stackoverflow.com/a/10185427/345716) 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...
Contributor guide
Assessment
This issue has not been assessed yet.