mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
bd597db829
- This is part of the quest to separate the frontend and server & get rid of all the places where there are cross-requires - At the moment the settings cache is one big shared cache used by the frontend and server liberally - This change doesn't really solve the fundamental problems, as we still depend on events, and requires from inside frontend - However it allows us to control the misuse slightly better by getting rid of restricted requires and turning on that eslint ruleset
29 lines
762 B
JavaScript
29 lines
762 B
JavaScript
const router = require('./lib/router');
|
|
const registerHelpers = require('./lib/helpers');
|
|
const urlUtils = require('../../../shared/url-utils');
|
|
|
|
// Dirty requires
|
|
const settingsCache = require('../../../shared/settings-cache');
|
|
|
|
function ampRouter(req, res) {
|
|
if (settingsCache.get('amp') === true) {
|
|
return router.apply(this, arguments);
|
|
} else {
|
|
// routeKeywords.amp: 'amp'
|
|
let redirectUrl = req.originalUrl.replace(/\/amp\//, '/');
|
|
|
|
urlUtils.redirect301(res, redirectUrl);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
activate: function activate(ghost) {
|
|
// routeKeywords.amp: 'amp'
|
|
let ampRoute = '*/amp/';
|
|
|
|
ghost.routeService.registerRouter(ampRoute, ampRouter);
|
|
|
|
registerHelpers(ghost);
|
|
}
|
|
};
|