I using https.createServer to create a secure connection server, however, it won't work on my custom port http://localhost:2019.
Following is my code:
const options = {
key:fs.readFileSync('security/privkey1.pem'),
cert:fs.readFileSync('security/cert1.pem')
}
const app = express()
const https = require('https').createServer(options, app).listen(2019)
app.use(function(req, res, next) {
console.log("checking secure connection")
if(req.secure){
next();
}else{
res.redirect('https://' + req.headers.host + req.url);
}
});
When I access to https://localhost:2019, it work perfectly but when I access to http://localhost:2019, it won't reach the server (the console didn't print "checking secure connection").
Nodejs expert please advise please advise.
Thank you.