Check if the given request is HTTPS
npm install is-https

Install package:
``bash`
yarn add is-httpsor
npm install is-https
`js`
const isHTTPS = require('is-https')
// or
import isHTTPS from 'is-https'
`ts`
function isHTTPS(req: IncomingMessage, trustProxy: Boolean = true): Boolean | undefined
isHTTPS function tries to use 2 different methods for HTTPS detection:
- Test if x-forwarded-proto header contains httpstrustProxy
- Can be disabled by setting argument to falsereq.connection.encrypted
- Test if is true
Returns either true or false based on checks or undefined if no check was reliable.
TIP: If you want to redirect users from http to https, it is better using isHTTPS(req) === false` to avoid redirect loops.
- redirect-ssl - Connect middleware to enforce HTTPS
MIT