diff --git a/website/public/js/services/questServices.js b/website/public/js/services/questServices.js index 9483837d7b..18fcc393c6 100644 --- a/website/public/js/services/questServices.js +++ b/website/public/js/services/questServices.js @@ -16,7 +16,7 @@ function questsFactory($rootScope,Content,Groups,User,Analytics) { var user = User.user; - var party = $rootScope.party; + var party = Groups.party(); function lockQuest(quest,ignoreLevel) { if (!ignoreLevel){ @@ -31,7 +31,7 @@ if (item.unlockCondition && item.unlockCondition.condition === 'party invite') { if (!confirm(window.env.t('mustInviteFriend'))) return; - return Groups.inviteOrStartParty(Groups.party()); + return Groups.inviteOrStartParty(party); } if (item.previous && (!User.user.achievements.quests || (User.user.achievements.quests && !User.user.achievements.quests[item.previous]))){ return alert(window.env.t('unlockByQuesting', {title: Content.quests[item.previous].text()})); @@ -87,7 +87,7 @@ function questInit(){ Analytics.track({'hitType':'event','eventCategory':'behavior','eventAction':'quest','owner':true,'response':'accept','questName':$rootScope.selectedQuest.key}); - Analytics.updateUser({'partyID':party.id,'partySize':party.memberCount}); + Analytics.updateUser({'partyID':party._id,'partySize':party.memberCount}); party.$questAccept({key:$rootScope.selectedQuest.key}, function(){ party.$get(); $rootScope.$state.go('options.social.party'); diff --git a/website/src/middleware.js b/website/src/middleware.js index de99b461b1..8de23aab6c 100644 --- a/website/src/middleware.js +++ b/website/src/middleware.js @@ -87,16 +87,32 @@ module.exports.errorHandler = function(err, req, res, next) { res.json(500,{err:message}); //res.end(err.message); } +function isHTTP(req) { + var baseUrl = nconf.get("BASE_URL"); + + return ( + req.headers['x-forwarded-proto'] && + req.headers['x-forwarded-proto'] !== 'https' && + nconf.get('NODE_ENV') === 'production' && + baseUrl.indexOf('https') === 0 + ); +} + +function isProxied(req) { + return ( + req.headers['x-habitica-lb'] && + req.headers['x-habitica-lb'] === 'Yes' + ); +} module.exports.forceSSL = function(req, res, next){ var baseUrl = nconf.get("BASE_URL"); - // Note x-forwarded-proto is used by Heroku & nginx, you'll have to do something different if you're not using those - if (req.headers['x-forwarded-proto'] && req.headers['x-forwarded-proto'] !== 'https' - && nconf.get('NODE_ENV') === 'production' - && baseUrl.indexOf('https') === 0) { + + if(isHTTP(req) && !isProxied(req)) { return res.redirect(baseUrl + req.url); } - next() + + next(); } module.exports.cors = function(req, res, next) {