current-url
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i current-url

Weekly Downloads

443

Version

2.3.0

License

MIT

Unpacked Size

7.12 kB

Total Files

10

Last publish

Collaborators

  • alexmendes