
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
canonical-host
Advanced tools
Redirect users to the canonical hostname for your site.
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!')
})
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.
FAQs
Redirect users to the canonical hostname for your site.
We found that canonical-host demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.