I have running server nodeJs with express module. And website is made by React.js which is server-side-redering.
And I have domain : www.example.com, Route53 with load balancer applied AWS Certificate Manager.
the problem is I don't know how to automatically access https:// protocol, when I type url http://www.example.com
now, I can access each of url like as http://www.example.com
or https://www.example.com
I found solution :
app.use (function (enter code herereq, res, next) {
if (req.secure) {
next();
} else {
res.redirect('https://' + req.headers.host + req.url);
}
});
but it's not working...
what is nice way???
update
if using nodejs with express, how to set a port? the express block port 80, So I use
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
. is it common method to connect port?I have load balancer using SSL (ACM), and port using port are 80, 443. how to directly access that either 'http' or 'https should access https.