From da5e67f9ad86201b24f93fbd428e31174af481cd Mon Sep 17 00:00:00 2001 From: Jonathan Cremin Date: Sat, 6 Dec 2014 14:46:30 +0000 Subject: [PATCH] Add variable to request for user's protocol --- app.js | 5 ++++- routes/share.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 18e84ed..14c6ce9 100644 --- a/app.js +++ b/app.js @@ -52,9 +52,12 @@ app.use(function(req, res, next) { app.get('*', function(req,res,next) { if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') { res.redirect("https://" + req.headers['host'] + req.url); + } else if (req.headers['cf-visitor']) { + req.userProtocol = "https"; } else { - next(); + req.userProtocol = "http" } + next(); }); app.get('/', function(req, res) { diff --git a/routes/share.js b/routes/share.js index 205b5ad..c8317e1 100644 --- a/routes/share.js +++ b/routes/share.js @@ -30,7 +30,7 @@ module.exports = function(req, res, next) { page: type, title: doc.items[0].name + " by " + doc.items[0].artist.name, items: doc.items, - thisUrl: req.protocol + '://' + req.get('host') + req.originalUrl + thisUrl: req.userProtocol + '://' + req.get('host') + req.originalUrl }); } else { Q.timeout(services[serviceId].lookupId(itemId, type), 5000).then(function(item) { @@ -63,7 +63,7 @@ module.exports = function(req, res, next) { page: type, title: item.name + " by " + item.artist.name, items: items, - thisUrl: req.protocol + '://' + req.get('host') + req.originalUrl + thisUrl: req.userProtocol + '://' + req.get('host') + req.originalUrl }); }); }, function(error) {