This module returns whether a request is under https
yarn add is-req-https2
- Node.js
- Express
- Hapi
If one of the following test is true, the function immediately return true.
- Check if
req.connection.encrypted
exist. - Check the property
req.secure
. - Check the
x-forwarded-proto
in headers - Check
req.server.info.protocol
for Hapi requests
Otherwise the function returns false.
import isHttps from 'is-req-https2';
// for express users
app.use((req, res, next) => {
req.isSecure = isHttps(req);
next();
});