Add variable to request for user's protocol
This commit is contained in:
parent
01c7f418dc
commit
da5e67f9ad
2 changed files with 6 additions and 3 deletions
5
app.js
5
app.js
|
@ -52,9 +52,12 @@ app.use(function(req, res, next) {
|
||||||
app.get('*', function(req,res,next) {
|
app.get('*', function(req,res,next) {
|
||||||
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
|
if (req.headers['cf-visitor'] && req.headers['cf-visitor'] != '{"scheme":"https"}') {
|
||||||
res.redirect("https://" + req.headers['host'] + req.url);
|
res.redirect("https://" + req.headers['host'] + req.url);
|
||||||
|
} else if (req.headers['cf-visitor']) {
|
||||||
|
req.userProtocol = "https";
|
||||||
} else {
|
} else {
|
||||||
next();
|
req.userProtocol = "http"
|
||||||
}
|
}
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/', function(req, res) {
|
app.get('/', function(req, res) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ module.exports = function(req, res, next) {
|
||||||
page: type,
|
page: type,
|
||||||
title: doc.items[0].name + " by " + doc.items[0].artist.name,
|
title: doc.items[0].name + " by " + doc.items[0].artist.name,
|
||||||
items: doc.items,
|
items: doc.items,
|
||||||
thisUrl: req.protocol + '://' + req.get('host') + req.originalUrl
|
thisUrl: req.userProtocol + '://' + req.get('host') + req.originalUrl
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Q.timeout(services[serviceId].lookupId(itemId, type), 5000).then(function(item) {
|
Q.timeout(services[serviceId].lookupId(itemId, type), 5000).then(function(item) {
|
||||||
|
@ -63,7 +63,7 @@ module.exports = function(req, res, next) {
|
||||||
page: type,
|
page: type,
|
||||||
title: item.name + " by " + item.artist.name,
|
title: item.name + " by " + item.artist.name,
|
||||||
items: items,
|
items: items,
|
||||||
thisUrl: req.protocol + '://' + req.get('host') + req.originalUrl
|
thisUrl: req.userProtocol + '://' + req.get('host') + req.originalUrl
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue