🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

canonical-host

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canonical-host

Redirect users to the canonical hostname for your site.

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

canonical-host

Redirect users to the canonical hostname for your site.

Usage

var canon = require('canonical-host')('my-site.com', 'other-site.com')

http.createServer(function (req, res) {
  // returns 'true' if it's taking over
  if (!canon(req, res)) return

  // now we know that they're visiting either my-site.com
  // or other-site.com
  res.end('Hello from the proper host name!')
})

canon(hosts..., [statusCode=301])

Pass in the request, the response, 1 or more hostnames to accept, and optionally a statusCode to send with the redirect.

If the host arg has https:// in front of it, then it will be redirected to https if it's not https already. Likewise if it starts with http:// and is already https.

Returns a function that takes a req/res pair, and which returns true if it redirected, false otherwise.

Keywords

redirect

FAQs

Package last updated on 20 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts