0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Make HTTPS compatible with a Ghost module

closes #4434
- Change an incorrect redirect
This commit is contained in:
Josh Vanderwillik 2014-11-11 19:02:38 -05:00 committed by Mark Stosberg
parent e07ec3ef84
commit 094d6dfc38

View file

@ -178,6 +178,7 @@ function checkSSL(req, res, next) {
if (isSSLrequired(res.isAdmin)) {
if (!req.secure) {
var forceAdminSSL = config.forceAdminSSL,
configUrl,
redirectUrl;
// Check if forceAdminSSL: { redirect: false } is set, which means
@ -186,12 +187,20 @@ function checkSSL(req, res, next) {
return res.sendStatus(403);
}
redirectUrl = url.parse(config.urlSSL || config.url);
configUrl = url.parse(config.urlSSL || config.url);
redirectUrl = configUrl.path;
if (req.url[0] === '/' && redirectUrl[redirectUrl.length - 1] === '/') {
redirectUrl += req.url.slice(1);
} else {
redirectUrl += req.url;
}
return res.redirect(301, url.format({
protocol: 'https:',
hostname: redirectUrl.hostname,
port: redirectUrl.port,
pathname: req.path,
hostname: configUrl.hostname,
port: configUrl.port,
pathname: redirectUrl,
query: req.query
}));
}