0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00
ghost/core/frontend/services/theme-engine/middleware/update-local-template-options.js
Hannah Wolfe b29852b012
🔥 Removed support for http/https mixed mode (#14783)
closes: https://github.com/TryGhost/Toolbox/issues/324
refs: https://github.com/TryGhost/Ghost/issues/14446

- Currently, if url is configured to http but a request is marked secure, Ghost will handle upgrading all internal URLs to https so that there are no mixed content warnings
- From 5.0 that feature is going away, in favour of strictly honouring the configured URL
- Ghost will serve URLs exactly as configured and won't upgrade http to https anymore
- This use case was common when Ghost was first built, but in 2022 the web is mostly https.
- The code needed to support the feature creates a lot of additional complexity & maintenance overhead, so removing this gives us space to do more cool and useful stuff in 2022
2022-05-11 14:53:23 +01:00

54 lines
2 KiB
JavaScript

const _ = require('lodash');
const hbs = require('../engine');
const urlUtils = require('../../../../shared/url-utils');
const customThemeSettingsCache = require('../../../../shared/custom-theme-settings-cache');
const preview = require('../preview');
function updateLocalTemplateOptions(req, res, next) {
const localTemplateOptions = hbs.getLocalTemplateOptions(res.locals);
// adjust @site.url for http/https based on the incoming request
const siteData = {
url: urlUtils.urlFor('home', {trailingSlash: false}, true)
};
// @TODO: it would be nicer if this was proper middleware somehow...
const previewData = preview.handle(req, Object.keys(customThemeSettingsCache.getAll()));
// strip custom off of preview data so it doesn't get merged into @site
const customData = previewData.custom;
delete previewData.custom;
// update site data with any preview values from the request
Object.assign(siteData, previewData);
const member = req.member ? {
uuid: req.member.uuid,
email: req.member.email,
name: req.member.name,
firstname: req.member.name && req.member.name.split(' ')[0],
avatar_image: req.member.avatar_image,
subscriptions: req.member.subscriptions && req.member.subscriptions.map((sub) => {
return Object.assign({}, sub, {
default_payment_card_last4: sub.default_payment_card_last4 || '****'
});
}),
paid: req.member.status !== 'free',
status: req.member.status,
products: req.member.products
} : null;
hbs.updateLocalTemplateOptions(res.locals, _.merge({}, localTemplateOptions, {
data: {
member: member,
site: siteData,
custom: customData,
// @deprecated: a gscan warning for @blog was added before 3.0 which replaced it with @site
blog: siteData
}
}));
next();
}
module.exports = updateLocalTemplateOptions;