https-scheme

1.0.1 • Public • Published

https-scheme

redirects window location to HTTPS scheme

KLP

Usage

Just add this line of code in your JavaScript client code.

require('https-scheme')()

Or, if you prefer maybe cause you want to call it if some condition is met, for instance only in production

const forceHttps = require('https-scheme')
 
if (isProduction) {
  forceHttps()
}

Annotated source

Check if protocol is https. If yes, redirect location to homonym secure URL.

function forceHttps () {
  if (window.location.protocol !== 'https:') {
    window.location.href = 'https:' + window.location.href.substring(window.location.protocol.length)
  }
}
 
module.exports = exports.default = forceHttps

License

MIT

Package Sidebar

Install

npm i https-scheme

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

2.99 kB

Total Files

4

Last publish

Collaborators

  • fibo