Thursday, 18 May 2017

heroku ssl setup ok but doesn't redirect the node js app to https

I have enabled Automated Certificate Management on heroku for my nodeJS app: I followed this link.

I did :

heroku certs:auto -a myApp

and the result was that the ssl is enabled on this app.
When I go to the app url, mydomain.com, I don't see the green ssl on url bar. But if I manually prefix the domain to https:// mydomain.com , then I see it.
How can I automatically redirect every user to https version of the site?
My current related code in the server.js file, I don't know if this part is related to my issue:

var portfinder = require('portfinder');
if (!port) {
    portfinder.basePort = 8080;
    portfinder.getPort(function (err, pt) {
        if (err) throw err;
        port = pt;
        app.listen(port, function () {
            if (argv.o) {
                opener('http://127.0.0.1:' + port.toString());
            }
            console.log('Example app listening on port 8080!')
        });
    });
}else{
    app.listen(port, function () {
        if (argv.o) {
            opener('http://127.0.0.1:' + port.toString());
        }
        console.log('Example app listening on port 8080!')
    });
}



via passion

No comments:

Post a Comment