Skip to content

Request: Introduce a req.completeURL() method #4697

Open
@pmorch

Description

@pmorch

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...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions