alexandermendes / current-url

Get the current URL isomorphically.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

current-url

npm version

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

Installation

yarn add current-url

Usage

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.

Options

ignoreProxies

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.

About

Get the current URL isomorphically.


Languages

Language:TypeScript 91.3%Language:JavaScript 8.7%