Request: Introduce a `req.completeURL()` method

Open
#4,697 3 comments 4 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Domain
api, backend

Research direction

Start by reviewing Express's request properties named in the issue: req.originURL, req.protocol, req.get('host'), and req.originalUrl, then compare them with the linked Stack Overflow recommendation. The work is done when Express provides a consistently named complete-URL request method whose behavior covers the reported full URL example.

Written by the indexing model from the issue text.

Description

discuss enhancement ideas

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

Dominant language
JavaScript
Stars
69.7k
Forks
25.6k
Avg merge
2d 9h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from expressjs/express

All issues in expressjs/express

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.