Skip to content

bergos/absolute-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Attaches .absoluteUrl() function to req

Resources

License

Stars

Watchers

Forks

Packages

No packages published