HashtagSell / htsApp

HashtagSell Beta Application
0 stars 0 forks source link

http redirect to https within htsApp #63

Closed that1guy closed 9 years ago

that1guy commented 9 years ago

I've attempted to resolve this inside server.js in htsApp. We shall see if this works.

that1guy commented 9 years ago

@brozeph

that1guy commented 9 years ago

@brozeph, should I do this within server.js in htsApp or should we do it inside load balancer.

This isn't working at moment.

//force HTTPS if request is coming from production or staging
app.use(function(req, res, next) {
    var host = req.get('host');

    if(host === "hashtagsell.com" || host === "www.hashtagsell.com" ) {

        host = "www.hashtagsell.com";  //Force url to always contain www

        if ((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) { //If not https
            res.redirect('https://' + host + req.url); //force https
        } else {
            next();
        }
    } else if(host === "staging.hashtagsell.com") {

        if ((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) { //If not https
            res.redirect('https://' + host + req.url); //force https
        } else {
            next();
        }
    } else  {
        next();
    }
});
that1guy commented 9 years ago

Resolved by configuring AWS LB to handle redirect. Thanks @brozeph