Question

By default dotcloud allows me to access my node instance via HTTPS, but i should allow only the HTTPS and forward every HTTP request to HTTPS.

How should I do it on dotcloud platform?

Thanks in advance!

Was it helpful?

Solution

dotCloud provides an additional header: x-forwarded-proto which allows you to know the proxy source.

In your code you can use req.headers['x-forwarded-proto'] ( is either 'http' or 'https' ) to know the source. When it's http you can then redirect to the https.

OTHER TIPS

It should be the same way as any other node.js application hosted elsewhere.

Have you tried the solutions in these answers?

How to force SSL / https in Express.js

Automatic HTTPS connection/redirect with node.js/express

Works! Thanks guys!

connectApp.use(function(req, res, next){
    if( req.headers['x-forwarded-proto'] && req.headers['x-forwarded-proto'] == "http" )
        res.redirect( 'https://' + global.config.server.address );
    else
        next();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top