Get the current URL isomorphically.
Respects the following HTTP headers:
Host
Forwarded
X-Forwarded-Proto
X-Forwarded-Protocol
X-Url-Scheme
Front-End-Https
X-Forwarded-Ssl
X-Forwarded-Host
X-Forwarded-Port
X-Replaced-Path
yarn add current-url
In the browser call the function with no arguments:
import { currentUrl } from 'current-url';
currentUrl();
On the server call the function with a Node HTTP request object as the first argument:
import { currentUrl } from 'current-url';
currentUrl(req);
// Ignore proxies
currentUrl(req, { ignoreProxies: true });
In both cases the function returns a URL
object.
Type: object
Default: false
By default, the currentUrl
function will take into account potential URL
rewrites made by proxies, load balancers, etc. along the way (as long as these
append special HTTP headers to the request). Use this option to disable that
behaviour.