'Express req.protocol always returns https

I have an server running express. It uses req.protocol to force https. However, when I visit the site on http, it still give https.

Here is the function:

 app.use((req, res, next)=>{
        console.log(req.protocol);
        if(req.protocol === "https"){
            next();
        }else{
            res.redirect(`https://${req.headers.host}${req.url}`);
        }
    });

It isn't redirecting and therefore the site isn't working. What can I do to fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source