absolute-url

v1.0.0
Attaches .absoluteUrl() function to req
absolute url

absolute-url

build status npm version

Get the absolute URL of an Express request object.

Install

npm install --save absolute-url

Usage

The library offers two ways to use the functionality:

Function

The default export is a function that can be called with the Express request object as a parameter. It returns the absolute URL as a URL object.

import absoluteUrl from 'absolute-url'

app.use((req, res, next) => {
  console.log(absoluteUrl(req))

  next()
})

See examples/function.js for a full working example.

Middleware

The package also exports a middleware factory function. It can be used to attach a .absoluteUrl method to the Express request object. The method returns the absolute URL as a URL object.

import { middleware } from 'absolute-url'

app.use(middleware())

app.use((req, res, next) => {
  console.log(req.absoluteUrl())

  next()
})

See examples/middleware.js for a full working example.

Metadata

  • MIT
  • Whatever
  • Thomas Bergwinkl
  • released 3/28/2016

Downloads

Maintainers