0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/frontend/meta/url.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

48 lines
2 KiB
JavaScript

const urlUtils = require('../../shared/url-utils');
const urlService = require('../../server/services/url');
const {checks} = require('../services/data');
// This cleans the url from any `/amp` postfixes, so we'll never
// output a url with `/amp` in the end, except for the needed `amphtml`
// canonical link, which is rendered by `getAmpUrl`.
function sanitizeAmpUrl(url) {
if (url.indexOf('/amp/') !== -1) {
url = url.replace(/\/amp\/$/i, '/');
}
return url;
}
function getUrl(data, absolute) {
if (checks.isPost(data)) {
/**
* @NOTE
*
* We return the post preview url if you are making use of the `{{url}}` helper and the post is not published.
* If we don't do it, we can break Disqus a bit. See https://github.com/TryGhost/Ghost/issues/9727.
*
* This short term fix needs a better solution than this, because this is inconsistent with our private API. The
* private API would still return /404/ for drafts. The public API doesn't serve any drafts - nothing we have to
* worry about. We first would like to see if this resolves the Disqus bug when commenting on preview pages.
*
* A long term solution should be part of the final version of Dynamic Routing.
*/
if (data.status !== 'published' && urlService.getUrlByResourceId(data.id) === '/404/') {
return urlUtils.urlFor({relativeUrl: urlUtils.urlJoin('/p', data.uuid, '/')}, null, absolute);
}
return urlService.getUrlByResourceId(data.id, {absolute: absolute, withSubdirectory: true});
}
if (checks.isTag(data) || checks.isUser(data)) {
return urlService.getUrlByResourceId(data.id, {absolute: absolute, withSubdirectory: true});
}
if (checks.isNav(data)) {
return urlUtils.urlFor('nav', {nav: data}, absolute);
}
// sanitize any trailing `/amp` in the url
return sanitizeAmpUrl(urlUtils.urlFor(data, {}, absolute));
}
module.exports = getUrl;